BookmarkSubscribeRSS Feed
YH
Calcite | Level 5 YH
Calcite | Level 5

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!

4 REPLIES 4
RobPratt
SAS Super FREQ

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

YH
Calcite | Level 5 YH
Calcite | Level 5

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!

RobPratt
SAS Super FREQ

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.

YH
Calcite | Level 5 YH
Calcite | Level 5

Hi RobPatt,

Thank you a lot for your help!

sas-innovate-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 933 views
  • 3 likes
  • 2 in conversation