Open
Description
Versions: Pyomo: 5.7.3 Python: 3.7.8
I'm starting to use the interface CPLEXDirect to avoid temporary files and reducing processing time in small problems. I usually introduce parameters in ConcreteModels as DataFrames. I solve my model like this:
import pyomo.environ as pe
opt = pe.SolverFactory('cplex_direct')
model = create_toy_model()
results = opt.solve(model)
When I create my model in this way it works fine:
def create_toy_model():
model = pe.ConcreteModel()
model.x1 = pe.Var(within=pe.NonNegativeReals)
model.x2 = pe.Var(within=pe.NonNegativeReals)
model.obj = pe.Objective(expr=2 * model.x1 + 2 * model.x2, sense=pe.maximize)
model.con1 = pe.Constraint(expr=model.x1 + 2 * model.x2 >= 2)
model.con2 = pe.Constraint(expr=model.x1 + 2 * model.x2 <= 4)
return model
However when using DataFrame in the model:
def create_toy_model():
import pandas as pd
A = pd.DataFrame({0: [1, 1], 1: [2, 2]})
B = pd.DataFrame({0: [2, 4]})
C = pd.DataFrame({0: [2], 1: [2]})
model = pe.ConcreteModel()
model.x1 = pe.Var(within=pe.NonNegativeReals)
model.x2 = pe.Var(within=pe.NonNegativeReals)
model.obj = pe.Objective(expr=model.x1 * C.at[0, 0] + model.x2 * C.at[0, 1], sense=pe.maximize)
model.con1 = pe.Constraint(expr=model.x1 * A.at[0, 0] + model.x2 * A.at[0, 1] >= B.at[0, 0])
model.con2 = pe.Constraint(expr=model.x1 * A.at[1, 0] + model.x2 * A.at[1, 1] <= B.at[1, 0])
return model
I get an error:
TypeError: non-float value in input sequence (2)
This error disappears when defining the df with dtype='float16'. The issue is related with the distinction between data types int and numpy.int.