BookmarkSubscribeRSS Feed
erroltauro
Calcite | Level 5

proc optmodel;

set supply= {"S1","S2"};
set distr= {"SGD","MYD","IDD","VND","THD"};
set plant= {"SG","MY","ID","VN","TH"};

number Suppliercap {supply}=[2000,2000];

number AnnualDemand {plant}=[
150 300 150 150 300];

number timeperiods = 6;

number matcost = 40;
number packcost = 5;

number Leg1Trcost {supply,distr}=[
12 12 14 16 18

14 12 14 18 16] ;

number Leg2Trcost {distr,plant}=[
0 4 4 6 5
3 0 4 4 5
3 4 0 4 6
5 4 6 0 3
5 6 4 3 0];

number Pmin = 1;
number Pmax = 5;
var Firstlegsupply {supply,distr} >= 0;
var Secondlegsupply {distr,plant} >= 0;
var open {distr} binary;

minimize Total_Cost= sum {i in supply,k in distr} Firstlegsupply[i,k]*(Leg1Trcost[i,k]+matcost) +
sum {k in distr,j in plant} Secondlegsupply[k,j]*(Leg2Trcost[k,j]+matcost+packcost);

con MaxS {i in supply} :
sum {k in distr} Firstlegsupply[i,k] <= Suppliercap[i];

con MinD {j in plant} :
sum {k in distr} Secondlegsupply[k,j]*timeperiods = AnnualDemand[j];

con NoStock {k in distr} :
sum {i in supply} Firstlegsupply[i,k] = sum {j in plant} Secondlegsupply[k,j];

con linkingcons{k in distr,j in plant}:
Secondlegsupply[k,j]-2000*open[k]<=0;

con mindistr :
sum{k in distr}open[k]>= Pmin;
con maxdistr :
sum{k in distr}open[k]<= Pmax;

con minqty{k in distr,j in plant}:
Secondlegsupply[k,j]<=25;

con maxqty{k in distr,j in plant}:
Secondlegsupply[k,j]<=100;


solve;

print Total_Cost;

print {k in distr} (sum {i in supply} Firstlegsupply[i,k]);

print Secondlegsupply;


quit;

 

The above is my code which will output Total cost, and flows during 2 legs of material supply.

In addition to this i want to seperately print Transportation cost during both legs for the optimized quantities.i.e.

 

1.  sum {i in supply,k in distr} Firstlegsupply[i,k]*Leg1Trcost[i,k];

2. sum {k in distr,j in plant} Secondlegsupply[k,j]*Leg2Trcost[k,j];

 

Could you kindly advise on how to write code for this. 

Do i need to define additional variables and assign this equation. As you can see this is portion of objective function. And i want the function to calculate the value based on optimised values for FirstLegsupply and Secondlegsupply. 

 

3 REPLIES 3
RobPratt
SAS Super FREQ
Just use PRINT with parentheses:
print (your expression);
erroltauro
Calcite | Level 5

Hello Rob, 

 

Thank you very much for your response. I am very sorry for my ignorance as I am new to this software. 

 

I had tried the same but without using parentheses.

With your suggestion, I am able to print the value and they appear just as a number. 

 

In order that the results displayed are self-explanatory,  may I know how to associate it with a name.  Example for the objective function, the result is displayed as Total_cost and then the numeric value. 

 

Your response is highly appreciated and will be of great help. 

 

Regards, 

Errol Tauro 

 

 

RobPratt
SAS Super FREQ

Here are four ways:

   print "my string";
   print (expression);

   print "my string" (expression);

   impvar myimpvar = expression;
   print myimpvar;

   num mynum = expression with .sol suffix for each variable;
   print mynum;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Discussion stats
  • 3 replies
  • 1348 views
  • 0 likes
  • 2 in conversation