I am hoping someone will be able to point me in the direction of why I am experiencing floating-point outputs rather than simply model.X = [15,15] and model.Z = [15,5] as solutions to this model?
Note that I use a piece-wise constraint to determine the relationship between Z and X.
Scroll down to see the outputs from the model solver.
Code
from pyomo.core import *
# Define the model type
model = ConcreteModel()
# Piecewise components - index and variables
model.INDEX1 = Set(dimen=1, initialize=[0,1])
model.X = Var(model.INDEX1, bounds=(5,15))
model.Z = Var(model.INDEX1)
# For indexed variables, the following must be python dictionaries with keys the same as the variable index
DOMAIN_PTS = {0: [5, 10, 15], 1: [5, 10, 15]}
RANGE_PTS = {0: [30, 20, 15], 1: [5, 5, 5]}
# Set piecewise constraint
model.linearized_constraint = Piecewise(model.INDEX1, # indexing sets
model.Z,model.X, # range and domain variables
pw_pts=DOMAIN_PTS,
pw_constr_type='EQ',
pw_repn='INC',
f_rule=RANGE_PTS,
unbounded_domain_var = False)
# Maximize the sumproduct of z and x over the index
model.obj = Objective(expr= sum(model.Z[i] * model.X[i] for i in model.INDEX1) , sense=maximize)
opt = SolverFactory('gurobi')
opt.options['NonConvex'] = 2
obj_val = opt.solve(model)
# Print results
print([value(model.X[i]) for i in model.INDEX1])
print([value(model.Z[i]) for i in model.INDEX1])
Output
**WARNING: Piecewise component 'linearized_constraint[(1,)]' has detected slopes of consecutive piecewise segments to be within 1e-08 of one another. Refer to the Piecewise help documentation for information on how to disable this warning.
[14.890257352941177, 15.0]
[15.109742647058823, 5.0]
model.X = Var(model.INDEX1, bounds=(5,15), domain=PositiveIntegers)
. $\endgroup$