# Controller consisting of multiple separate networks. # MultiNetwork.tz (c) 2011 Jacob Schrum. # See Simulation.tz for more copyright information @include "FreeNetwork.tz" # Only reason to inherit from FreeNetwork is to maintain all the book-keeping # methods. The actual implementation of MultiNetwork is based on separate networks # stored in the list "networks" FreeNetwork : MultiNetwork { + variables: networks (list). current-mode (int). + to set-networks to nets (list): i (int). networks = nets. for i = 0, i < |networks|, i++ : { self add-dependency on (networks{i}). } + to set-mode to mode (int): update (int). update = (current-mode != mode). if update : { current-mode = mode. controller update-hud-network-view. } + to get-network index i (int): return (networks{i}). + to current-net: return (self get-network index current-mode). + to num-networks: return ( |networks| ). + to archive: i (int). for i = 0, i < |networks|, i++ : { networks{i} archive. } return 1. + to dearchive: i (int). for i = 0, i < |networks|, i++ : { networks{i} dearchive. } return 1. + to copy: i (int). newNet (object). temp (list). newNet = new MultiNetwork. newNet set-age to (self get-age). newNet set-stats scores (self get-average-scores) evals (self get-number-evaluations) ss (self get-sums-of-squares). newNet set-number-inputs to number-inputs. newNet set-number-outputs to number-outputs. temp = {}. for i = 0, i < |(self get-mode-ages)|, i++ : { push ((self get-mode-ages){i}) onto temp. } newNet set-mode-ages to temp. temp = {}. for i=0, i<|networks|, i++ : { push (networks{i} copy) onto temp. } newNet set-networks to temp. return newNet. + to run-with inputs inputList (list): networks{current-mode} run-with inputs inputList. + to flush: i (int). for i = 0, i < |networks|, i++ : { (networks{i} flush). } + to get-output at-position position (int): return (networks{current-mode} get-output at-position position). + to get-all-outputs: return (networks{current-mode} get-all-outputs). + to print-network: i (int). for i = 0, i < |networks|, i++ : { print "Network: $i". (networks{i} print-network). } + to destroy: i (int). for i = 0, i < |networks|, i++ : { free (networks{i}). } free networks. + to is-closed: i (int). result (int). result = 1. for i = 0, i < |networks|, i++ : { if (!(networks{i} is-closed)) : { result = 0. print "Network $i not closed: ". networks{i} print-network. } } return result. + to get-input-connectivity: i (int). result (list). result = (networks{0} get-input-connectivity). for i = 1, i < |networks|, i++ : { result = ((controller get-list-ops) list-or lhs (result) rhs (networks{i} get-input-connectivity)). } return result. + to get-number-of-nodes: i (int). sum (int). sum = 0. for i = 0, i < |networks|, i++ : { sum += (networks{i} get-number-of-nodes). } return sum. }