How to use the pyomo.environ.ConcreteModel function in Pyomo

To help you get started, we’ve selected a few Pyomo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github coin-or / rbfopt / tests / test_rbfopt_degree1_models.py View on Github external
def test_create_max_h_k_model(self):
        """Test the create_max_h_k_model function.

        This test simply checks whether the function returns a valid
        pyomo.ConcreteModel object.
        """
        model = d1.create_max_h_k_model(self.settings, self.n, self.k,
                                        self.var_lower, self.var_upper,
                                        self.integer_vars, None,
                                        self.node_pos, self.rbf_lambda,
                                        self.rbf_h, self.Amat, -1)
        self.assertIsInstance(model, pyomo.environ.ConcreteModel)
github coin-or / rbfopt / tests / test_rbfopt_degree1_models.py View on Github external
def test_create_max_h_k_model(self):
        """Test the create_max_h_k_model function.

        This test simply checks whether the function returns a valid
        pyomo.ConcreteModel object.
        """
        model = d1.create_max_h_k_model(self.settings, self.n, self.k,
                                        self.var_lower, self.var_upper,
                                        self.integer_vars, None, self.node_pos,
                                        self.rbf_lambda, self.rbf_h,
                                        self.Amat, -1)
        self.assertIsInstance(model, pyomo.environ.ConcreteModel)
github IDAES / idaes-pse / idaes / examples / ripe_python / isotsim.py View on Github external
def pyomosim(x0):
        # Define rate parameters 
        flow = 1.0
        vol = 1.0
        gc = 8.314
        # Define kinetic rate parameters
        k = params        
        a0,b0,c0,d0,e0 = np.array(x0).T.tolist()
        opt = pyo.SolverFactory('baron')
        model = pyo.ConcreteModel()
#        bound_ub = 100
        # Define model variables
        model.a = pyo.Var(domain = pyo.NonNegativeReals)#, bounds = (0.0,bound_ub))
        model.b = pyo.Var(domain = pyo.NonNegativeReals)#, bounds = (0.0,bound_ub))
        model.c = pyo.Var(domain = pyo.NonNegativeReals)#, bounds = (0.0,bound_ub))
        model.d = pyo.Var(domain = pyo.NonNegativeReals)#, bounds = (0.0,bound_ub))
        model.e = pyo.Var(domain = pyo.NonNegativeReals)#, bounds = (0.0,bound_ub))
        model.dset = pyo.RangeSet(5)
        model.dum = pyo.Var(model.dset)

        model.r1 = pyo.Var(domain = pyo.Reals)
        model.r2 = pyo.Var(domain = pyo.Reals)
        model.r3 = pyo.Var(domain = pyo.Reals)
        
        def fr1(model):
            return model.r1 == k[0] * model.a * model.b
github FZJ-IEK3-VSA / FINE / FINE / expansionModules / robustPipelineSizing.py View on Github external
if isinstance(dic_diam_costs, dict):
        for diam in dic_diam_costs.keys():
            utils.isStrictlyPositiveNumber(diam)
            utils.isStrictlyPositiveNumber(dic_diam_costs[diam])
    else:
        raise TypeError("The input has to be a dictionary")
    if not isinstance(robust, bool):
        raise TypeError("The input has to be a bool")
    utils.isString(solver)
    utils.isPositiveNumber(verbose)

    # set list of available diameters
    diameters = dic_diam_costs.keys()

    # build concrete pyomo model
    model = py.ConcreteModel()

    # sets for nodes, arcs, diameters, scenarios
    model.nodes = py.Set(initialize=graph.nodes)
    model.arcs = py.Set(initialize=list(distances.keys()), dimen=2)
    # diameters assuming that each pipe has the same diameter options
    model.diameters = py.Set(initialize=diameters)
    # if we have special scenarios, scenario names are tuples, otherwise not
    if robust:
        # set indices for each scenario by its nodePair = (startnode, endnode)
        model.scenarios = py.Set(initialize=specialScenarioNames, dimen=2)
    else:
        # set indices for each timeStep number
        model.scenarios = py.Set(initialize=specialScenarioNames, dimen=1)

    # create variables binaries x are the same for each scenario
    # pressure variables are different for each scenario
github Pyomo / pyomo / pyomo / contrib / parmest / examples / rooney_biegler / all_in_one.py View on Github external
def generate_model(data):
    
    h = int(data['hour'])
    y = float(data['y'])
    
    model = pyo.ConcreteModel()
    model.asymptote = pyo.Var(initialize=15)
    model.rate_constant = pyo.Var(initialize=0.5)

    def response_rule(m):
        expr = m.asymptote * (1 - pyo.exp(-m.rate_constant * h))
        return expr

    model.response_function = pyo.Expression(rule=response_rule)

    def SSE_rule(m):
        return (y - m.response_function) ** 2

    def ComputeFirstStageCost_rule(m):
        return 0

    model.FirstStageCost = pyo.Expression(rule=ComputeFirstStageCost_rule)
github Pyomo / pyomo / doc / attic / old_sphinx_files / getting_started / spyfiles / spy4scripts.py View on Github external
###NOTE: as of May 16, this will not even come close to running. DLW
### and it is "wrong" in a lot of places.
### Someone should edit this file, then delete these comment lines. DLW may 16

"""
David L. Woodruff and Mingye Yang, Spring 2018
Code snippets for scripts.rst in testable form
"""
import pyomo.environ as pyo

instance = pyo.ConcreteModel()
instance.I = pyo.Set(initialize=[1,2,3])
instance.sigma = pyo.Param(mutable=True, initialize=2.3)
instance.Theta = pyo.Param(instance.I, mutable=True)
for i in instance.I:
    instance.Theta[i] = i
ParamName = "Theta"
idx = 1
NewVal = 1134

# @Assign_value_to_indexed_parametername
instance.ParamName[idx].value = NewVal
# @Assign_value_to_indexed_parametername

ParamName = "sigma"

# @Assign_value_to_unindexed_parametername_2
github FZJ-IEK3-VSA / FINE / FINE / energySystemModel.py View on Github external
"""
        # Get starting time of the optimization to, later on, obtain the total run time of the optimize function call
        timeStart = time.time()

        # Check correctness of inputs
        utils.checkDeclareOptimizationProblemInput(timeSeriesAggregation, self.isTimeSeriesDataClustered)

        ################################################################################################################
        #                           Initialize mathematical model (ConcreteModel) instance                             #
        ################################################################################################################

        # Initialize a pyomo ConcreteModel which will be used to store the mathematical formulation of the model.
        # The ConcreteModel instance is stored in the EnergySystemModel instance, which makes it available for
        # post-processing or debugging. A pyomo Suffix with the name dual is declared to make dual values associated
        # to the model's constraints available after optimization.
        self.pyM = pyomo.ConcreteModel()
        pyM = self.pyM
        pyM.dual = pyomo.Suffix(direction=pyomo.Suffix.IMPORT)

        # Set time sets for the model instance
        self.declareTimeSets(pyM, timeSeriesAggregation)

        ################################################################################################################
        #                         Declare component specific sets, variables and constraints                           #
        ################################################################################################################

        for key, mdl in self.componentModelingDict.items():
            _t = time.time()
            utils.output('Declaring sets, variables and constraints for ' + key, self.verbose, 0)
            utils.output('\tdeclaring sets... ', self.verbose, 0), mdl.declareSets(self, pyM)
            utils.output('\tdeclaring variables... ', self.verbose, 0), mdl.declareVariables(self, pyM)
            utils.output('\tdeclaring constraints... ', self.verbose, 0), mdl.declareComponentConstraints(self, pyM)
github IDAES / idaes-pse / idaes / surrogate / ripe / emsampling.py View on Github external
def ripesim(data):
        import pyomo.environ as pyo

        # ripesim expects input in a particular order
        model = pyo.ConcreteModel()
        # s is index over species
        model.s = pyo.RangeSet(ns)
        # r over reactions
        model.r = pyo.RangeSet(nr)
        # initialize variable from data
        model.conc0 = pyo.Param(
            model.s, initialize=dict(((s), data[s - 1]) for s in model.s)
        )
        if ptype > 1:
            model.T = pyo.Param(initialize=data[ns])
            model.E = pyo.Param(
                model.r, initialize=dict(((r), acte[r - 1]) for r in model.r)
            )

        model.nu = pyo.Param(
            model.r,
github Pyomo / pyomo / pyomo / contrib / benders / examples / farmer.py View on Github external
def create_master(farmer):
    m = pe.ConcreteModel()

    m.crops = pe.Set(initialize=farmer.crops, ordered=True)
    m.scenarios = pe.Set(initialize=farmer.scenarios, ordered=True)

    m.devoted_acreage = pe.Var(m.crops, bounds=(0, farmer.total_acreage))
    m.eta = pe.Var(m.scenarios)
    for s in m.scenarios:
        m.eta[s].setlb(-432000 * farmer.scenario_probabilities[s])

    m.total_acreage_con = pe.Constraint(expr=sum(m.devoted_acreage.values()) <= farmer.total_acreage)

    m.obj = pe.Objective(expr=sum(farmer.PlantingCostPerAcre[crop] * m.devoted_acreage[crop] for crop in m.crops) + sum(m.eta.values()))
    return m
github IDAES / idaes-pse / idaes / surrogate / pysmo / polynomial_regression.py View on Github external
"""

        The ``poly_predict_output`` method generates output predictions for input data x_data based a previously generated polynomial fitting.

        Args:
            results_vector  : Python object containing results of polynomial fit generated by calling the poly_training function.
            x_data          : Numpy array of designs for which the output is to be evaluated/predicted.

        Returns:
             Numpy Array    : Output variable predictions based on the polynomial fit.

        """
        nf = x_data.shape[1]
        x_list = [i for i in range(0, nf)]
        import pyomo.environ as aml
        m = aml.ConcreteModel()
        i = aml.Set(initialize=x_list)
        m.xx = aml.Var(i)
        m.o2 = aml.Objective(expr=results_vector.generate_expression([m.xx[i] for i in x_list]))
        y_eq = np.zeros((x_data.shape[0], 1))
        for j in range(0, x_data.shape[0]):
            for i in x_list:
                m.xx[i] = x_data[j, i]
            y_eq[j, 0] = aml.value(m.o2([m.xx[i] for i in x_list]))
        return y_eq