1

Suppose I have a status array, where each status is within the integer domain, how can I utilize pyomo to assign the individual cells appropriately?

In the following snippet I simplified this by enforcing the solver to assign fixed values taken from of model.instance_range to model.var_array

Code Snippet

import pyomo.environ as pe

model = pe.ConcreteModel()
model.instance_range = pe.RangeSet(1,3)
model.array_range = pe.RangeSet(1,10)
model.var_array = pe.Var(model.array_range, initialize=0, bounds = (0,5),within=pe.Integers )

def assign_instance_range(model, instance):
    return sum(model.var_array[i] == instance for i in model.array_range) == 1
model.c = pe.Constraint(model.instance_range, rule=assign_instance_range)

def dummy_objective(model):
    return sum(model.var_array[slot].value for slot in range(1,4))
model.objective = pe.Objective(rule=dummy_objective, sense=pe.maximize)

optimizer = pe.SolverFactory("mindtpy")
results = optimizer.solve(model, tee=True)
model.var_array.pprint()

I was expecting assign_instance_range is constraining the solver in a way, that he must assign each value from model.instance_range exactly once (i.e. model.var_array would end up with sth. like [3,0,2,1,0,0,0,0,0,0]). Apparently instead, it got lost in a seemingly infeasibility after only 1 iteration, of which I'm not sure where he got lost:

Output / Analytics

INFO: ---Starting MindtPy---
INFO: Original model has 3 constraints (0 nonlinear) and 0 disjunctions, with
    10 variables, of which 0 are binary, 10 are integer, and 0 are continuous.
INFO: rNLP is the initial strategy being used.
INFO: Relaxed NLP: Solve relaxed integrality
WARNING: Loading a SolverResults object with a warning status into
    model.name="unknown";
      - termination condition: infeasible
      - message from solver: Ipopt 3.14.5\x3a Converged to a locally
        infeasible point. Problem may be infeasible.
INFO: Initial relaxed NLP problem is infeasible. Problem may be infeasible.
INFO: ---MindtPy main Iteration 1---
INFO: MIP 1: Solve main problem.
WARNING: Constant objective detected, replacing with a placeholder to prevent
    solver failure.
INFO: Algorithm should terminate here.
var_array : Size=10, Index=array_range
    Key : Lower : Value : Upper : Fixed : Stale : Domain
      1 :     0 :     0 :     5 : False : False : Integers
      2 :     0 :     0 :     5 : False : False : Integers
      3 :     0 :     0 :     5 : False : False : Integers
      4 :     0 :     0 :     5 : False : False : Integers
      5 :     0 :     0 :     5 : False : False : Integers
      6 :     0 :     0 :     5 : False : False : Integers
      7 :     0 :     0 :     5 : False : False : Integers
      8 :     0 :     0 :     5 : False : False : Integers
      9 :     0 :     0 :     5 : False : False : Integers
     10 :     0 :     0 :     5 : False : False : Integers

But how to use pyomo then to assign many variables other than to specify them as separate, non-array variables? - which would not be manageable due to the amount of variables in the actual context (>500) and especially to keep it flexible.

Thanks in advance!

frunk
  • 15
  • 4

0 Answers0