Decrease the size of a set in a for loop (in C++)

Hello,
first time using this website…hope I am writing in the correct category! :slightly_smiling_face:

I need to decrease the size of a set in a for loop (in C++) in order to reduce the amount of constraint the solver has to deal with.

I defined set Jc := {jMin…jIt}; in my .mod file then in the C++ code I assigned values of jMin and jIt which change in the for loop. Before the solve I tried to do let Jc := Jc diff J2D; but I get the following error
Error executing “let” command: Jc has an = assignment in the model.

Therefore, based on a suggestion found online, I tried to change the definition of the set in the .mod file set Jc default {jMin…jIt}; which got rid of the error but significantly increased the number of constraint and also the constraint eliminated by presolve…

Any idea or suggestions?

Thanks
Sam

1 Like

Hi @Samuele_Viaro,

Wellcome to the discourse forum!

It is odd that using default increased the number of constraints. For instance:

param jMin;
param jIt;
set Jc default {jMin..jIt};

let jMin := 1;
let jIt := 10;
set J2D;

let J2D := {1, 2, 3};
let Jc := Jc diff J2D;
display Jc;

let J2D := {4, 5};
let Jc := Jc diff J2D;
display Jc;

let J2D := {6, 7};
let Jc := Jc diff J2D;
display Jc;

produces the output:

set Jc := 4 5 6 7 8 9 10;

set Jc := 6 7 8 9 10;

set Jc := 8 9 10;

At each iteration the elements from J2D are removed from Jc, which I believe is what you want.

Could you please check the values of J2D and Jc (before and after each let Jc := Jc diff J2D;)?

Thanks for the quick response!
I made it work…there was a mistake with a definition of another set… :hugs:

2 Likes