Skip to content
Advertisement

Pyomo find minimal sum of list values

I want to have an indexed binary variable so pyomo optimises it to minimise the total sum of the list while picking at least 2 elements. When I remove the (imo redundant) model.q I receive:

ValueError: No variables appear in the Pyomo model constraints or objective. This is not supported by the NL file interface

and the solution pyomo gives me with model.q contains q=0 which violates constraint c1.

JavaScript
JavaScript

Advertisement

Answer

Welcome to the site.

You have a couple errors that are causing you problems.

  1. when you construct your parameter, you need to pass in a dictionary so that pyomo can associate the items in the set to the values. You cannot pass in a list and assume things happen sequentially… The set could have any ordering, etc.

  2. You have a hideous typo when making your constraint C2. See my note in code comment

  3. Your variable q is totally unnecessary. And, by multiplying q times y you are making the problem non-linear by multiplying variables.

A little fixed up:

JavaScript

produces (a little long but I think it will help you to look at ALL 3 of these items…

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement