reset password
Author Message
justinch0w
Posts: 5
Posted 22:00 Nov 06, 2019 |
When I initialize an array like this
set of int: GridSize = 1 .. 4;

array [GridSize,GridSize] of var int: Answer;
var int: row1 = 1;

constraint 1 == row1 -> Answer[1,1] = 1;

the part of the array that are not populated are represented as "-2147483646".

How do i check if the array element is empty and replace it with a 0 with Geocode 6.1.1 without it crashing/taking forever to run.

Last edited by justinch0w at 22:01 Nov 06, 2019.
rabbott
Posts: 1649
Posted 22:37 Nov 06, 2019 |

Not quite sure what you are asking. You can always do something like this.

constraint Answer[1, 1] == 0;

Or

constraint not is_fixed(Answer[1, 1]) -> Answer[1, 1] == 0;

 

is_fixed is true/false depending on whether its argument has a value. The line above gives Answer[1, 1] a value if it doesn't already have one. I'm suspicious about using it, though, since it seems too procedural.

rabbott
Posts: 1649
Posted 22:51 Nov 06, 2019 |

P.S. Since   x -> y   is logically the same as  not x \/ y, 

constraint    not is_fixed(Answer[1, 1]) -> Answer[1, 1] == 0; 

is logically the same as  

constraint    is_fixed(Answer[1, 1]) \/ Answer[1, 1] == 0;

That seems more declarative. It gives the solver the option of either finding a value on its own for  Answer[1,1]  or treating it as having value 0 when no value has been established.

Last edited by rabbott at 08:25 Nov 07, 2019.