Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
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