Operations Research topics: SAS/OR,
SAS Optimization, and SAS Simulation Studio

Optimization Model Expression

Reply
Occasional Contributor YH
Occasional Contributor
Posts: 10

Optimization Model Expression

Hi Everyone,

I have some questions about data set definition in an optimization model.

One of the constraints is: sum {i in DivBlocks, j in Pages} BlockSize * BlockAssign[i,j] <= MaxDivPrntArea.

But I do not know how to create the data set of MaxDivPrntArea, can you tell me how to create it?

PS: the length of  MaxDivPrntArea may be different from  MaxDivPrntArea[k'] when k is not equal k'.

Thank you very much for your help!

SAS Employee
Posts: 447

Re: Optimization Model Expression

The index set for MaxDivPrntArea should match (or be a subset of) the index set for your constraint.  More explicitly, suppose you have a SAS data set called mydata that contains k and MaxDivPrntArea.  Then you need something like this:

set KSET;

num MaxDivPrntArea {KSET};

read data mydata into KSET= MaxDivPrntArea;

con Mycon {k in KSET}:

     sum {i in DivBlocks, j in Pages} BlockSize * BlockAssign[i,j] <= MaxDivPrntArea;

Or are you having trouble creating the mydata SAS data set itself?

In any case, you might find it useful to read some of the examples here:

SAS/OR(R) 13.2 User's Guide: Mathematical Programming Examples

Occasional Contributor YH
Occasional Contributor
Posts: 10

Re: Optimization Model Expression

Hi RobPratt,

Thank you for your answers! I am not sure how to create DivBlocks either.

I want to create a set DivBlocks which has 2 levels indices: 1. index k for the first level; 2. given a particular level, DivBlocks, there is a set DivBlocks = {x, y, z, ...}. For different DivBlocks, they have different elements. For example, DivBlocks[1] = {1,2,5}, DivBlocks[2] = {3,7}, DivBlocks[3] = {4,6,8,9}.

Because the length of the first level of DivBlocks may change for different applications, I think it would be better not to list them one by one. Could you help me to get the answers? Thank you for your kind help!

SAS Employee
Posts: 447

Re: Optimization Model Expression

First create a SAS data set as follows:

data indata;

   input k i;

   datalines;

1 1

1 2

1 5

2 3

2 7

3 4

3 6

3 8

3 9

;

In PROC OPTMODEL, you can read these pairs like this:

   set <num,num> KI;

   read data indata into KI=[k i];

One approach to express the desired constraint is to use an implicit slice:

   set KSET = setof {<k,i> in KI} k;

   con Mycon {k in KSET}:
      sum {<(k),i> in KI, j in Pages} BlockSize * BlockAssign[i,j] <= MaxDivPrntArea;

If you insist on using DivBlocks, here is an alternative approach that uses the SETOF operator again:

   set DivBlocks {k in KSET} = setof {<(k),i> in KI} i;

   con Mycon {k in KSET}:

     sum {i in DivBlocks, j in Pages} BlockSize * BlockAssign[i,j] <= MaxDivPrntArea;

A third approach passes through the KI set only once to construct both KSET and DivBlocks:

   set KSET init {};

   set DivBlocks {KSET} init {};

   for {<k,i> in KI} do;

      KSET = KSET union {k};

      DivBlocks = DivBlocks union {i};

   end;

   con Mycon {k in KSET}:

     sum {i in DivBlocks, j in Pages} BlockSize * BlockAssign[i,j] <= MaxDivPrntArea;

The doc link referenced in my previous reply contains numerous relevant examples.  Search for "sets indexed by other sets" in the pdf.

Occasional Contributor YH
Occasional Contributor
Posts: 10

Re: Optimization Model Expression

Hi RobPatt,

Thank you a lot for your help!

Ask a Question
Discussion stats
  • 4 replies
  • 365 views
  • 3 likes
  • 2 in conversation