I just started to learn about Pyomo. In several tutorials it is stated that the command for creating a variable is just model.Variable = VAR(...)
. However, I get the error message when using the Var function:
NameError: name 'Var' is not defined
Why do I get this error? Here you see my full code (the problematic statement is the last line):
import pyomo.environ as pyo
model = pyo.ConcreteModel()
#Sets
#empty set
model.A = pyo.Set()
#initialized set with values
model.D = pyo.Set(initialize=['red', 'green', 'blue'])
#Define a function to create ta sequence of numbers
def createSequenceOfNumbers(startNumber, endNumber):
return (i for i in range (startNumber, endNumber + 1))
model.C = pyo.Set(initialize=createSequenceOfNumbers(4, 9))
model.E = pyo.RangeSet(5,9)
#printing a set
model.C.pprint()
model.D.pprint()
model.E.pprint()
#Parameter
#define sets
model.A_P = pyo.RangeSet(1,3)
model.B_P = pyo.RangeSet(1,3)
#Values for the sets by using a dict-datatype.
valuesForParam = {}
valuesForParam [1,1] = 1
valuesForParam [1,3] = 2
valuesForParam [2,3] = 10
#define Parameters (2 dimensional)
model.P = pyo.Param(model.A_P, model.B_P, initialize=valuesForParam, default=0)
model.P.pprint()
#Variables
model.variable1 = Var(within=NonNegativeReals, bounds =(0,6), initialize=1.5)
pyo.Var
instead of justVar
$\endgroup$pyo.NonNegativeReals
$\endgroup$