BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
carenman
Fluorite | Level 6

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 resultscode 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.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

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);

View solution in original post

4 REPLIES 4
RobPratt
SAS Super FREQ
con difcolrow: alldiff({i in column} (x[i]-y[i]));
carenman
Fluorite | Level 6

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?

RobPratt
SAS Super FREQ

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);
carenman
Fluorite | Level 6

This workaround worked perfectly. Thanks a lot.

 

I am using SAS Studio, web based. I guess it is not the latest version:

 

Release: 3.6 (Enterprise Edition)

Supported browsers:
  • Microsoft Internet Explorer 11
  • Mozilla Firefox 21+
  • Google Chrome 27+
  • Apple Safari 6.0+ (on Apple OS X)

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.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

Discussion stats
  • 4 replies
  • 1523 views
  • 0 likes
  • 2 in conversation