Setting an integer constraint outside the variable declaration

23 views
Skip to first unread message

Geoffrey Brent

unread,
Oct 4, 2017, 10:49:26 PM10/4/17
to am...@googlegroups.com

I want to selectively set and disable integer constraints on some variables in a model. Something like this:

set index_values := {"A","B","C","D"};
set index_subset := {"B","D"};

var x{index_values};

subject to SomeIntegerConstraints{i in index_subset}: x[i] integer;
# force x[i] to take integer values for i in index_subset;


with the option to then drop and undrop the integer constraint later on, as I would with other constraint types.

But so far, the only way I've found to set an integer constraint is as part of the variable declaration. I can suppress integer constraints with option relax_integrality 1, but this is all-or-nothing; it doesn't allow me to selectively disable just some of the integer constraints.

I can work around the issue by adding extra variables and constraints:

var integer_values{index_subset} integer;
subject to ForceIntegers{i in index_subset}: x[i]=integer_values[i];

which effectively sets an integer constraint on those values, and then I can disable/enable that constraint by dropping/undropping ForceIntegers. But this seems a bit clumsy. Is there a better way to do this?

Cheers - Geoffrey

Dr. Geoffrey Brent

Assistant Director (a/g)

National Accounts Branch |  Macroeconomic Statistics Division |  Australian Bureau of Statistics

(P) (03) 9615 7685   (M) 0422 65 35 26

(E) geoffre...@abs.gov.au  (W)  www.abs.gov.au


The ABS Privacy Policy outlines how the ABS will handle any personal information that you provide to us.

Robert Fourer

unread,
Oct 5, 2017, 10:22:18 PM10/5/17
to am...@googlegroups.com
Yes, there is a simpler way. You can write

var x {index_values} integer;
...
let {i in index_subset} x[i].relax := 1;

In general, setting x[i].relax to 1 relaxes integrality, and setting it back to 0 requires integrality again. Initially the .relax values of all variables are 0, but .relax is ignored except for integer or binary variables. There's more in chapter 11 of the AMPL book, beginning at http://ampl.com/BOOK/CHAPTERS/14-command.pdf#page=13.

Bob Fourer
am...@googlegroups.com

=======

gpb...@gmail.com

unread,
Nov 12, 2017, 12:16:11 PM11/12/17
to AMPL Modeling Language
Thanks Robert! Sorry to be so long in replying, took me a while to realise that I should be looking for a response here and not in my inbox.

I ended up doing it a different way:

var x {index_values};
var integer_dummy {index_subset} integer;
subject to enforce_integrality {i in index_subset}: x[i] = integer_dummy[i];

and then dropping/undropping enforce_integrality as needed to switch rounding on/off. Are there any problems with doing it this way?

Thanks again - Geoffrey

Robert Fourer

unread,
Nov 13, 2017, 11:08:14 AM11/13/17
to am...@googlegroups.com
Your approach will get you the solutions that you are looking for. It will tend to slow the processing in AMPL and in the solver, due to the introduction of the extra variables and constraints indexed over index_subset, but you shouldn't worry about that unless you run into serious difficulties with solution times.

Bob Fourer
am...@googlegroups.com

=======
Reply all
Reply to author
Forward
0 new messages