Hi there,
I am unable to use alldiff within a constraint. My intention is to constrain all results from difcolrow to be different from each other. I am using SAS Studio (web based).
Find below a code with an example using >=-3 in the difcolrow constraint to illustrate what I mean:
proc optmodel;
set column={'1','2','3','4'};
set row={'1','2','3','4'};
var x{column} >=1 <=4 integer;
var y{row} >=1 <=4 integer;
con alldiff(x);
con alldiff(y);
con difcolrow{i in column}: x[i]-y[i]>=-3;
solve; print x y difcolrow.body; quit;code results
As you can see the difcolrow has several results equal to zero. What I want is all this difcolrow values to be also all different from each other.
I tried too use alldiff in the constraint in different ways, but I got continuous code errors:
con difcolrow{i in column}: alldiff(x[i]-y[i]);
It is possible to do it using alldiff? Any other idea about how to do it? Thanks a lot.
Here's a workaround if you are not using the latest release:
var diff {column} integer;
con diffcon {i in column}: diff[i] = x[i] - y[i];
con difcolrow: alldiff(diff);
con difcolrow: alldiff({i in column} (x[i]-y[i]));
Thanks for the reply RobPratt.
I tried your solution and I still get some code errors:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
59
60 proc optmodel;
61
62 set column={'1','2','3','4'};
63 set row={'1','2','3','4'};
64
65 var x{column} >=1 <=4 integer;
66 var y{row} >=1 <=4 integer;
67
68 con alldiff(x);
69 con alldiff(y);
70 con difcolrow: alldiff({i in column} (x[i]-y[i]));
_ _ _
22 79 621
200
ERROR 22-322: Expecting a name.
ERROR 79-322: Expecting a {.
ERROR 621-782: Subscript 1 must be a string, found a number.
ERROR 200-322: The symbol is not recognized and will be ignored.
_
525
ERROR 525-782: The symbol 'i' is unknown.
_
76
ERROR 76-322: Syntax error, statement will be ignored.
70 ! con difcolrow: alldiff({i in column} (x[i]-y[i]));
_
22
ERROR 22-322: Syntax error, expecting one of the following: !!, *, **, +, ',', -, .., /, :, <>, ><, BY, CROSS, DIFF, ELSE, INTER,
SYMDIFF, TO, UNION, ^, ||, }.
71
72 solve;
Maybe ALLDIFF can only be applied to VAR and not to the result of operations made with VARS?
Here's a workaround if you are not using the latest release:
var diff {column} integer;
con diffcon {i in column}: diff[i] = x[i] - y[i];
con difcolrow: alldiff(diff);
This workaround worked perfectly. Thanks a lot.
I am using SAS Studio, web based. I guess it is not the latest version:
Build date: Apr 20, 2017 3:45:55 PM
SAS Mid-tier release: Apr 18, 2017 2:38:00 PM
Java Version: 1.7.0_111
SAS release: 9.04.01M4P11092016
SAS platform: Linux LIN X64 3.10.0-693.2.2.el7.x86_64
Site name: SAS ONDEMAND FOR ACADEMICS
Site number: 70094220
Copyright © 2012-2017, SAS Institute Inc., Cary, NC, USA.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.