Skip to content

Commit

Permalink
fix var = number to var.value = number; and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jialuw96 committed May 10, 2024
1 parent eb3b753 commit ba466c2
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions pyomo/contrib/doe/doe.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,14 +492,17 @@ def _direct_kaug(self):
# add objective function
mod.Obj = pyo.Objective(expr=0, sense=pyo.minimize)

# set ub and lb to parameters
# set parameters to given values
for par in self.param.keys():
cuid = pyo.ComponentUID(par)
var = cuid.find_component_on(mod)

# only set up bounds if they are variables
if var.ctype is Var:
var.fix(self.param[par])
# if it is a param, give it a new value
elif var.ctype is Param:
var.value = self.param[par]

# generate parameter name list and value dictionary with index
var_name = list(self.param.keys())
Expand Down Expand Up @@ -609,13 +612,25 @@ def _create_block(self):
self.create_model(mod=mod, model_option=ModelOptionLib.stage1)

# Fix parameter values in the copy of the stage1 model (if they exist)
#for par in self.param:
# cuid = pyo.ComponentUID(par)
# var = cuid.find_component_on(mod)
# if var is not None:
# # Fix the parameter value
# # Otherwise, the parameter does not exist on the stage 1 model
# var.fix(self.param[par])

for par in self.param:
cuid = pyo.ComponentUID(par)
var = cuid.find_component_on(mod)

if var is not None:
# Fix the parameter value
# Otherwise, the parameter does not exist on the stage 1 model
var.fix(self.param[par])
# if it is a variable, fix it to a new value
if var.ctype is Var:
var.fix(self.param[par])
# if it is a param, give it a new value
elif var.ctype is Param:
var.value = self.param[par]

def block_build(b, s):
# create block scenarios
Expand All @@ -642,7 +657,7 @@ def block_build(b, s):
var.fix(self.scenario_data.scenario[s][par])
# if it is a param, give it a new value
elif var.ctype is Param:
var = self.scenario_data.scenario[s][par]
var.value = self.scenario_data.scenario[s][par]

mod.block = pyo.Block(mod.scenario, rule=block_build)

Expand Down Expand Up @@ -1205,14 +1220,15 @@ def _fix_design(self, m, design_val, fix_opt=True, optimize_option=None):
if fix_opt:
var.fix(design_val[name])
else:
# Otherwise, unfix only the design variables listed in optimize_option with value True
if optimize_option is None:
var.unfix()
else:
if optimize_option[name]:
var.unfix()

elif var.ctype is Param:
var = design_val[name]
var.value = design_val[name]

return m

Expand Down

0 comments on commit ba466c2

Please sign in to comment.