Skip to main content
Question

Set of constraints

  • March 30, 2026
  • 1 reply
  • 9 views

Hi, 
I’m writing a program for a two MIP formulations with each a set of constraints. I would like to be able to compare the two in terms of computation time. Hence, I would like two set of constraints such that I can select the constraints needed for a formulation in the mathematical program. However, at the moment I have several constraints and a set as a subset of AllConstraints. Below, it shows a part of the code. I get the error: Expecting an element but the giben expression is of type reference in regards to the set Constraints1. How do I fix this?

    Set Constraints1 {
        Definition: {
            { charge_change, battery_max, battery_min, charging_limit, decharging_limit }
        }
    }
    Constraint charge_change {
        IndexDomain: t;
        Definition: e(t) = e(t-1) + Eta_c * p_charged(t) - p_decharged(t) / Eta_d;
    }
    Constraint battery_max {
        IndexDomain: t;
        Definition: e(t) <= S_max;
    }
    Constraint battery_min {
        IndexDomain: t;
        Definition: e(t) >= S_min;
    }
    Constraint charging_limit {
        IndexDomain: t;
        Definition: p_charged(t) <= P_c * (1 - d(t));
    }
    Constraint decharging_limit {
        IndexDomain: t;
        Definition: p_decharged(t) <= P_d * d(t);
    }

1 reply

gdiepen
AIMMS Champ
Forum|alt.badge.img+7
  • AIMMS Champ
  • March 31, 2026

In the code you paste, the set Constraints1 does not appear to be a subset of AllConstraints.

The error you are getting is probably caused by the fact that you are not including the elements within single quotes. The subset of AllConstraints needs to be filled with elements, which you do in AIMMS by using the single quotes (‘) around it.

 

Also pay special attention to variables when they have a definition, because these also create a constraint.

Instead of hard-coded elements in a set like Constraints1, I personally use the set operators in AIMMS and the fact that every section and declaraton section automatically introduces an implicit subset of allidentifiers.

 

So if you create a section in AIMMS with the name “Model 2” AIMMS will automatically introduce a new implicit set that is a subset of allidentifiers with the name “Model_2”. If you define all variables and constraints underneath this section, you can create a new set call sConstraintsModel2, make it a subset of AllConstraints and then give it the definition:

AllConstraints * Model_2

(This means it will do the set intersection, so only those elements that are both in AllConstraints and also in the subset Model_2)

 

If there are also constraints that are shared, you can can define them for example under section Shared_Model_1_and_2 and then make the definition of the sConstraintsModel2 as

AllConstraints * Model_2 + AllConstraints * Shared_Model_1_and_2

 

Alternatively, you can define a section called “Disabled constraints and variables” under the Model_2 section and ‘remove’ anything declared under this section with the definition

AllConstraints * Model_2 - AllConstraints * Disabled_constraints_and_variables

 

This way, during development you can easily disable a constraint by just moving it under the disabled constraints and variables section.

 

One big added advantage of this is that this will deal also with the situation where you rename a constraint. If you have hardcoded references using the single quotes, if you rename one of the constraints, you will have to also rename the element in the single quotes.

 

 

 


Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator