save network

This commit is contained in:
HaoYizhi 2023-03-14 21:20:38 +08:00
parent 4f7be2c76c
commit 9435484e3f
8 changed files with 9 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -93,6 +93,11 @@ class Model(ap.Model):
self.firm_network = ap.Network(self, G_Firm) self.firm_network = ap.Network(self, G_Firm)
self.product_network = ap.Network(self, G_bom) self.product_network = ap.Network(self, G_bom)
out_file = open("myfile.json", "w")
import json
json.dump(nx.adjacency_data(G_Firm), out_file)
out_file.close()
# init product # init product
for ag_node, attr in self.product_network.graph.nodes(data=True): for ag_node, attr in self.product_network.graph.nodes(data=True):
product = ProductAgent(self, code=ag_node.label, name=attr['Name']) product = ProductAgent(self, code=ag_node.label, name=attr['Name'])

1
myfile.json Normal file

File diff suppressed because one or more lines are too long

4
orm.py
View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from sqlalchemy import create_engine, inspect from sqlalchemy import create_engine, inspect
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, ForeignKey, BigInteger, DateTime, PickleType, Boolean from sqlalchemy import Column, Integer, String, ForeignKey, BigInteger, DateTime, PickleType, Boolean, Text
from sqlalchemy.sql import func from sqlalchemy.sql import func
from sqlalchemy.orm import relationship, Session from sqlalchemy.orm import relationship, Session
from sqlalchemy.pool import NullPool from sqlalchemy.pool import NullPool
@ -65,6 +65,8 @@ class Sample(Base):
ts_done = Column(DateTime(timezone=True), onupdate=func.now()) ts_done = Column(DateTime(timezone=True), onupdate=func.now())
stop_t = Column(Integer, nullable=True) stop_t = Column(Integer, nullable=True)
firm_network = Column(Text(4294000000), nullable=True)
experiment = relationship('Experiment', back_populates='sample', uselist=False) experiment = relationship('Experiment', back_populates='sample', uselist=False)
result = relationship('Result', back_populates='sample', lazy='dynamic') result = relationship('Result', back_populates='sample', lazy='dynamic')