本文整理汇总了Python中network.Network.run方法的典型用法代码示例。如果您正苦于以下问题:Python Network.run方法的具体用法?Python Network.run怎么用?Python Network.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network.Network
的用法示例。
在下文中一共展示了Network.run方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: evalOneMax
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import run [as 别名]
def evalOneMax(individual):
n = Network(4, 2, 5)
n.N_CONTENTS = 3 * 10 ** 4
n.N_WARMUP_REQUESTS = 4 * 10 ** 4
n.N_MEASURED_REQUESTS = 1 * 10 ** 4
n.GAMMA = 1
n.ALPHA = .8
n.INTERNAL_COST = 2
n.EXTERNAL_COST = 10
n.on_path = True
n.ind = individual
n.run()
return n.hits,
示例2: start_network_thread
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import run [as 别名]
def start_network_thread(nxt_handler):
running = True
while running:
try:
network = Network(nxt_handler)
running = network.run()
except Exception as ex:
logger.error(traceback.format_exc())
logger.error("Restarting Network")
time.sleep(1)
示例3: TestCoordClass
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import run [as 别名]
class TestCoordClass(unittest.TestCase):
def setUp(self):
""" initial setup"""
self.net = Network()
self.nc1 = NodeClass('simple_node_1', 0.1, 'coordbased', \
Sources(), self.net)
self.nc2 = NodeClass('simple_node_2', 0.1, 'coordbased', \
Sources(), self.net)
self.cc = CoordClass('coord', 0.1, 'coordbased', Sources(), self.net)
self.li = [self.nc1, self.nc2, self.cc]
self.nc1.node.protocol.initProtocol(self.li)
self.nc2.node.protocol.initProtocol(self.li)
self.cc.node.protocol.initProtocol(self.li)
self.net.NodeList = self.li
def testRun(self):
""" tests the run method. """
self.cc.run()
pass
def testIncomingMsgs(self):
""" tests the incomingMsgs method. """
# wrong test
initialize()
activate(self.cc, self.cc.incomingMsgs())
simulate(until=10)
self.assertTrue(self.cc.busy_cpu)
def test_sim(self):
""" tests a real simple small simulation. """
initialize()
for node in self.li:
activate(node, node.run())
activate(node, node.incomingMsgs())
self.net.run()
simulate(until=10)
self.assertTrue(self.cc.node.protocol.NodeList)
示例4: main
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import run [as 别名]
def main():
initialize()
env = Environment()
net = Network()
nl = []
for i in range(max_nodes):
n = NodeClass(i, '0.2', 'decentralized', Sources(), net)
nl.append(n)
# populate network with nodes
init_net_list(nl, net)
#init protocol
init_protocol_requirements(nl)
init_protocol_phase(nl, net)
print_results(nl)
# activate(net, net.run())
# for i, ncls in zip(range(len(nl)), nl):
for ncls in nl:
activate(ncls, ncls.run())
activate(net, net.run())
simulate(until=maxSimTime)
示例5: init_data
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import run [as 别名]
def init_data(port, data):
yield from port.send(data)
def send_data(node, port, data):
yield from node.out_ports[port].send(data)
if __name__ == "__main__":
graph = Graph('graph')
graph.add_node('d1', Display)
graph.add_node('d2', Display)
graph.add_edge('d1', 'out', 'd2', 'in')
graph.add_initial('hello', 'd1', 'in')
network = Network(graph)
network.run()
#port = Port('out')
#comp = MyComp()
#sched.new(port)
#sched.mainloop()
#port.send({'ports': [comp.in_ports['in']], 'data':'hello world'})
示例6: str
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import run [as 别名]
userFolder = str(sys.argv[2])
ownIP = str(sys.argv[3])
ownPort = int(sys.argv[4])
bootstrapIP = str(sys.argv[5])
bootstrapPort = int(sys.argv[6])
TCPPortStart = int(sys.argv[7])
TCPPortCount = int(sys.argv[8])
watcherIP = str(sys.argv[9])
else:
userName = "User1" #str(argv[1])
userFolder = "User1/" #str(argv[2])
ownIP = "localhost" #str(argv[3])
ownPort = 50001 #int(argv[4])
bootstrapIP = "localhost" #str(argv[5])
bootstrapPort = 50000 #int(argv[6])
TCPPortStart = 60010 #int(argv[7])
TCPPortCount = 10 #int(argv[8])
watcherIP = "localhost" #str(argv[9])
# initialize and start overlay layer
overlay = Overlay(userName, ownIP, ownPort, bootstrapIP, bootstrapPort, n2o, o2n, a2o, o2a, watcherQ)
application = Application(userFolder, o2a, a2o)
network1 = Network(userFolder, ownIP, ownPort, TCPPortStart, TCPPortCount, n2o, o2n, watcherQ, watcherIP, 2)
network1.run()
while not raw_input() == 'e':
pass
application.terminate()
overlay.terminate()
network1.terminate()
示例7: Model
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import run [as 别名]
class Model(object):
def __init__(self, name, dt=0.001, dtype=theano.config.floatX):
self.name = name
self.dtype = dtype
# self.network = network
self.network = Network(self.name)
self.t = 0
self.dt = dt
self.neuron_models = []
self.connections = []
def reset(self):
self.t = 0
for model in self.neuron_models:
model.reset()
for connection in self.connections:
connection.reset()
self.network.reset()
def build(self):
ensembles = self.network.all_ensembles
##################################################
### build all ensembles
for ensemble in ensembles:
ensemble.build(self.dtype)
##################################################
### make one big set of neurons for each neuron type
kinds = set(type(e.neurons) for e in ensembles)
# assert len(kinds) == 1 and kinds[0] == 'lif'
# neuron_model = type(ensembles[0].neurons)
self.neuron_models = []
for kind in kinds:
### count number of neurons
neurons = sum(e.neurons.size
for e in ensembles if isinstance(e.neurons, kind))
big_model = kind(neurons, mode='bigmodel')
big_model.build(self.dtype)
i = 0
for ensemble in ensembles:
big_model.link_model(ensemble.neurons, i)
i += ensemble.neurons.size
self.neuron_models.append(big_model)
##################################################
### Build other network components (inputs, probes, etc.)
self.network.build(self.dtype)
##################################################
### TODO: run neuron models here to estimate rates,
### then use these rates to find decoders
##################################################
self.connections = self.network.all_connections
for connection in self.connections:
connection.build(self.dtype)
def run(self, time):
if len(self.neuron_models) == 0:
raise Exception(
"Either no neurons have been added to the model, " +
"or the model has not been built yet.")
stop_time = self.t + time
### get probes to make buffers for the full runtime (it's faster)
for probe in self.network.all_probes:
if 2*probe.max_time < stop_time:
probe.max_time = stop_time
while self.t < stop_time:
self.t += self.dt
### reset inputs; connections will write to these inputs
# self.network.reset_input()
# for model in self.neuron_models:
# model.reset_input()
### update connections
for connection in self.connections:
connection.tick(self.dt)
### call ticks, this is where inputs get written from connections
self.network.tick(self.dt)
### run neuron models
#.........这里部分代码省略.........
示例8: Api
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import run [as 别名]
#.........这里部分代码省略.........
c.write = writestr
db.session.commit()
def addNewCardInDB(self, card):
script = " ".join(str(card.scripts_ids))
writestr = " ".join(str(card.write))
c = Cards.query.get(card.id)
# print c
if (c == None):
c = Cards(card.id, card.name, card.desc, card.column_id, card.project_id, ' '.join(card.tags), card.user_id, 0, writestr)
db.session.add(c)
else:
c.name = card.name
c.content = card.desc
c.column_id = card.column_id
c.tags = ' '.join(card.tags)
c.user_id = card.user_id
c.scripts_id = 0
c.write = writestr
db.session.commit()
def addNewUserInDB(self, user):
c = Users.query.get(user.id)
if (c == None):
c = Users(user.id, user.name, user.admin, "", user.mail, 1)
db.session.add(c)
else:
c.name = user.name
c.admin = user.admin
c.mail = user.mail
db.session.commit()
def run(self):
while 1:
self.network.run()
if len(self.network.getReadedStack()) != 0:
msg = Msg()
data = self.network.getReadedMessage()
# if (data != ""):
# print ">>>>>>" + data
msg.ParseFromString(data)
if (msg.target == message_pb2.CARDS):
if msg.command == message_pb2.ERROR:
print 'ERROR CARDS',
print msg.error.error_id
elif msg.command == message_pb2.DELETE:
cards = msg.cards
c = Cards.query.get(cards.id)
if c is None:
continue
db.session.delete(c)
db.session.commit()
dictcard = {'id' : cards.id, "project_id" : cards.project_id}
dictcard['type'] = 'delcard'
red.publish('ouane', json.dumps(dictcard))
else:
cards = msg.cards
if cards.id == 0:
print "SUCCESS"
continue
self.addNewCardInDB(cards)
# print "CARD",
# print [cards.id, cards.name, cards.desc, cards.column_id, cards.project_id, cards.tags,
# cards.user_id, cards.scripts_ids, cards.write]
dictcard = {'id' : cards.id, 'name' : cards.name, 'desc' : cards.desc, 'project_id' : cards.project_id, 'column_id' : cards.column_id}