def load(self, arg, namespaces=[None], profile_memory=0, report_timing=None): """ Load the model with data from a file, dictionary or DataPortal object. """ if report_timing is not None: deprecation_warning( "The report_timing argument to Model.load() is deprecated. " "Use pyomo.common.timing.report_timing() to enable reporting " "construction timing") if arg is None or isinstance(arg, str): dp = DataPortal(filename=arg, model=self) elif type(arg) is DataPortal: dp = arg elif type(arg) is dict: dp = DataPortal(data_dict=arg, model=self) elif isinstance(arg, SolverResults): if len(arg.solution): deprecation_warning( "The Model.load() method is deprecated for loading " "solutions stored in SolverResults objects. Call" "Model.solutions.load_from().", version='4.3.11323') self.solutions.load_from(arg) else: deprecation_warning( "The Model.load() method is deprecated for loading " "solutions stored in SolverResults objects. By default, " "results from solvers are immediately loaded into " "the original model instance.", version='4.3.11323') return else: msg = "Cannot load model model data from with object of type '%s'" raise ValueError(msg % str( type(arg) )) self._load_model_data(dp, namespaces, profile_memory=profile_memory)
def load(self, arg, namespaces=[None], profile_memory=0): """ Load the model with data from a file, dictionary or DataPortal object. """ if arg is None or isinstance(arg, str): dp = DataPortal(filename=arg, model=self) elif type(arg) is DataPortal: dp = arg elif type(arg) is dict: dp = DataPortal(data_dict=arg, model=self) else: msg = "Cannot load model model data from with object of type '%s'" raise ValueError(msg % str(type(arg))) self._load_model_data(dp, namespaces, profile_memory=profile_memory)
Created on Thu Dec 19 16:12:21 2019 @author: Silvia """ from __future__ import division from pyomo.opt import SolverFactory from pyomo.core import AbstractModel from pyomo.dataportal.DataPortal import DataPortal from pyomo.environ import * import pandas as pd from datetime import datetime ############ Create abstract model ########### model = AbstractModel() data = DataPortal() # ####################Define sets##################### #Name of all the nodes (primary and secondary substations) model.N = Set() data.load(filename='nodes.csv', set=model.N) #first row is not read #Allowed connections model.links = Set(dimen=2) #in the csv the values must be delimited by commas data.load(filename='links.csv', set=model.links) #Nodes are divided into two sets, as suggested in https://pyomo.readthedocs.io/en/stable/pyomo_modeling_components/Sets.html: # NodesOut[nodes] gives for each node all nodes that are connected to it via outgoing links # NodesIn[nodes] gives for each node all nodes that are connected to it via ingoing links
from __future__ import division from pyomo.opt import SolverFactory from pyomo.core import AbstractModel from pyomo.dataportal.DataPortal import DataPortal from pyomo.environ import * import pandas as pd from datetime import datetime ############ Create abstract model ########### model = AbstractModel() data = DataPortal() # ####################Define sets##################### #Name of all the nodes (primary and secondary substations) model.N = Set() data.load(filename='total_nodes.csv', set=model.N) model.SS = Set() data.load(filename='nodes.csv', set=model.SS) #Node corresponding to primary substation model.PS = Set() data.load(filename='PS.csv', set=model.PS) #Allowed connections model.links = Set(dimen=2) #in the csv the values must be delimited by commas data.load(filename='links.csv', set=model.links) #Nodes are divided into two sets, as suggested in https://pyomo.readthedocs.io/en/stable/pyomo_modeling_components/Sets.html:
""" Created on Thu Dec 19 16:12:21 2019 @author: Silvia """ from __future__ import division from pyomo.opt import SolverFactory from pyomo.core import AbstractModel from pyomo.dataportal.DataPortal import DataPortal from pyomo.environ import * import pandas as pd from datetime import datetime ############ Create abstract model ########### model = AbstractModel() data = DataPortal() #Parameter for multi cables analysis model.Cable_Types = Param() # ####################Define sets##################### #Name of all the nodes (primary and secondary substations) model.N = Set() data.load(filename='nodes.csv', set=model.N) #first row is not read #Node corresponding to primary substation model.PS = Set(within=model.N) data.load(filename='PS.csv', set=model.PS) #Allowed connections model.links = Set(dimen=2, within=model.N *