Resources

Getting Started Examples (clpg01)

/***************************************************************/
/*                                                             */
/*          S A S   S A M P L E   L I B R A R Y                */
/*                                                             */
/*    NAME: clpg01                                             */
/*   TITLE: Getting Started Examples (clpg01)                  */
/* PRODUCT: OR                                                 */
/*  SYSTEM: ALL                                                */
/*    KEYS: OR                                                 */
/*   PROCS: CLP                                                */
/*    DATA:                                                    */
/*                                                             */
/* SUPPORT:                             UPDATE:                */
/*     REF:                                                    */
/*    MISC: Examples from the Getting Started section of the   */
/*          CLP Procedure chapter of the Constraint            */
/*          Programming book.                                  */
/*                                                             */
/***************************************************************/

/*  Send More Money  */


proc clp dom=[0,9]                  /* Define the default domain */
         out=out;                   /* Name the output data set  */
   var S E N D M O R E M O N E Y;   /* Declare the variables     */
   lincon                           /* Linear constraints        */
                                    /* SEND + MORE = MONEY       */
      1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E
      =
      10000*M + 1000*O + 100*N  + 10*E + Y,
      S<>0,                         /* No leading zeros          */
      M<>0;
   alldiff();      /* All variables have pairwise distinct values*/
run;

proc print data=out noobs;
run;

/*  Eight Queens  */

proc clp out=out
         varselect=fifo; /* Variable Selection Strategy               */
   array A[8] (A1-A8);   /* Define the array A                        */
   var (A1-A8)=[1,8];    /* Define each of the variables in the array */
                         /* Initialize domains                        */
   /* A[i] is the row number of the queen in column i*/
   foreach(A, DIFF,  0); /* A[i] 's are pairwise distinct */
   foreach(A, DIFF, -1); /* A[i] - i 's are pairwise distinct */
   foreach(A, DIFF,  1); /* A[i] + i 's are pairwise distinct */
run;

proc print data=out noobs label;
   label A1=a A2=b A3=c A4=d
         A5=e A6=f A7=g A8=h;
run;