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

Proc Optmodel Error in sum statement

Reply
Occasional Contributor
Posts: 6

Proc Optmodel Error in sum statement

[ Edited ]

Hello,

 

Here, my Factories as well as my Crossdocks have a Fixed Cost.

I keep getting an error. Where is the mistake in my program?

 

Many thanks

 

 

Proc optmodel;

set Factories= {"Kansas","NorthCarolina","NewHampshire","SouthDakota"};
set DCs= {"Virginia","Missouri","California","Florida"};
set Crossdocks= {"Wisconsin","Minnesota","SouthCarolina"};

number incost{Factories,Crossdocks}=[
36 26 31
43 28 48
37 44 42
32 28 30
];

number outcost {Crossdocks,DCs}=[
37 29 15 26
30 42 40 20
16 27 46 42
];

number capacity {Factories}=[
37 19 42 25];

number demand {DCs}=[
3 12 15 15];

number FixedCost {Factories, Crossdocks}= [
500 650
220 950
200 800
180
];
number M = 1000000;
number MaxUse {Crossdocks}=[37 43 31];


var inflow {Factories,Crossdocks} >= 0;
var outflow {Crossdocks,DCs} >= 0;
var Y {Factories,Crossdocks} binary;

minimize Total_Cost= sum {j in Crossdocks}(sum{i in Factories}(inflow[i,j]*incost[i,j])+Y[i,j]*FixedCost[i,j])+sum{j in Crossdocks, k in DCs}outcost[j,k]*outflow[j,k];

con Max_Supply {i in Factories} : sum {j in Crossdocks} inflow[i,j] <=capacity[i];
con No_Stock {j in Crossdocks} : sum {i in Factories} inflow[i,j] = sum {k in DCs} outflow[j,k];
con Min_Demand {k in DCs} : sum {j in Crossdocks} outflow[j,k] >=demand[k];
con Max_Use{j in Crossdocks}: sum{i in Factories}inflow[i,j]<=MaxUse[j];
con Inspections {j in Crossdocks}: sum{i in Factories}inflow[i,j]<=M*Y[j];


solve;

print Total_Cost;
print inflow;
print outflow;

quit;

 

 

 

Super User
Posts: 18,580

Re: Proc Optmodel Error in sum statement

@jfm00 please note that I've moved to the optimization forum which is more applicable in your question and edited the subject title to be more descriptive. And I've edited your question to separate the question from the code. Additionally, here is the log from your code that may help someone answer your question, so they don't have to run everything.

 

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
59
60 Proc optmodel;
61
62 set Factories= {"Kansas","NorthCarolina","NewHampshire","SouthDakota"};
63 set DCs= {"Virginia","Missouri","California","Florida"};
64 set Crossdocks= {"Wisconsin","Minnesota","SouthCarolina"};
65
66 number incost{Factories,Crossdocks}=[
67 362631
68 432848
69 374442
70 322830
71 ];
72
73 number outcost {Crossdocks,DCs}=[
74 37291526
75 30424020
76 16274642
77 ];
78
79 number capacity {Factories}=[
80 37194225];
81
82 number demand {DCs}=[
83 3121515];
84
85 number FixedCost {Factories, Crossdocks}= [
86 500 650
87 220 950
88 200 800
89 180
90 ];
91 number M = 1000000;
92 number MaxUse {Crossdocks}=[374331];
93
94
95 var inflow {Factories,Crossdocks} >= 0;
96 var outflow {Crossdocks,DCs} >= 0;
97 var Y {Factories,Crossdocks} binary;
98
99 minimize Total_Cost= sum {j in Crossdocks}(sum{i in Factories}(inflow[i,j]*incost[i,j])+Y[i,j]*FixedCost[i,j])+sum{j in
_ _
525 525
_ _
621 621
99 ! Crossdocks, k in DCs}outcost[j,k]*outflow[j,k];
ERROR 525-782: The symbol 'i' is unknown.

ERROR 621-782: Subscript 1 must be a string, found a number.

100
101 con Max_Supply {i in Factories} : sum {j in Crossdocks} inflow[i,j] <=capacity[i];
102 con No_Stock {j in Crossdocks} : sum {i in Factories} inflow[i,j] = sum {k in DCs} outflow[j,k];
103 con Min_Demand {k in DCs} : sum {j in Crossdocks} outflow[j,k] >=demand[k];
104 con Max_Use{j in Crossdocks}: sum{i in Factories}inflow[i,j]<=MaxUse[j];
105 con Inspections {j in Crossdocks}: sum{i in Factories}inflow[i,j]<=M*Y[j];
_
618
ERROR 618-782: The subscript count does not match array 'Y', 1 NE 2.

106
107
108 solve;
NOTE: Problem generation will use 2 threads.
NOTE: Previous errors might cause the problem to be resolved incorrectly.
ERROR: The constraint 'Inspections' has an incomplete declaration.
NOTE: The problem has 36 variables (0 free, 0 fixed).
NOTE: The problem has 12 binary and 0 integer variables.
NOTE: The problem has 14 linear constraints (7 LE, 3 EQ, 4 GE, 0 range).
NOTE: The problem has 60 linear constraint coefficients.
NOTE: The problem has 0 nonlinear constraints (0 LE, 0 EQ, 0 GE, 0 range).
NOTE: The OPTMODEL presolver is disabled for linear problems.
NOTE: Unable to create problem instance due to previous errors.
109
110 print Total_Cost;
ERROR: The symbol 'Total_Cost' has no value at line 110 column 7.
111 print inflow;
112 print outflow;
113
114 quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE OPTMODEL used (Total process time):
real time 0.05 seconds
user cpu time 0.06 seconds
system cpu time 0.00 seconds
memory 2308.37k
OS Memory 26784.00k
Timestamp 06/18/2017 09:56:02 PM
Step Count 8 Switch Count 270
Page Faults 0
Page Reclaims 1187
Page Swaps 0
Voluntary Context Switches 1129
Involuntary Context Switches 1
Block Input Operations 0
Block Output Operations 200

115
116 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
128

SAS Employee
Posts: 448

Re: Proc Optmodel Error in sum statement

It looks like at least some of your errors are addressed by this related thread.

Occasional Contributor
Posts: 6

Re: Proc Optmodel Error in sum statement

Dear Rob,

Thanks for your message.

I have removed number M as well as constraint :

con Inspections {j in Crossdocks} : sum {i in Factories} inflow[i,j] <=M * Y[j];

It seems to work well now. Please, can you have a final look and tell me if everything is fine? I am getting no more any error messages.

 

proc optmodel;

set Factories= {'Kansas','NorthCarolina','NewHampshire','SouthDakota'};
set DCs= {'Virginia','Missouri','California','Florida'};
set Crossdocks= {'Wisconsin','Minnesota', 'SouthCarolina'};

number incost{Factories,Crossdocks}=[
36 26 31
43 28 48
37 44 42
32 28 30
];

number outcost {Crossdocks,DCs}=[
37 29 15 26
30 42 40 20
16 27 46 42
];

number capacity {Factories}=[
37 19 42 25];

number demand {DCs}=[
3 12 15 15];

number FixedCost {Factories,Crossdocks} = [500 220 200 180 650 950 800];
number MaxUse {Crossdocks} = [37 43 31];

var inflow {Factories,Crossdocks} >= 0;
var outflow {Crossdocks,DCs} >= 0;
var Y {Factories,Crossdocks} binary;

minimize TotalCost =sum {j in Crossdocks} ( sum {i in Factories} ( inflow[i,j]*incost[i,j] + Y[i,j]*FixedCost[i,j] )+sum {j in Crossdocks,k in DCs} outcost[j,k]*outflow[j,k]);

con Max_Supply {i in Factories} : sum {j in Crossdocks} inflow[i,j] <=capacity[i];
con No_Stock {j in Crossdocks} : sum {i in Factories} inflow[i,j] = sum {k in DCs} outflow[j,k];
con Min_Demand {k in DCs} : sum {j in Crossdocks} outflow[j,k] >=demand[k];
con Max_Use{j in Crossdocks} : sum {i in Factories} inflow[i,j] <=MaxUse[j];


solve;
print inflow outflow TotalCost;
quit;

 

Thank you 

SAS Employee
Posts: 448

Re: Proc Optmodel Error in sum statement

[ Edited ]

I still see a few issues:

  1. Either remove the second occurrence of "j in Crossdocks" in the objective or adjust your parentheses.
  2. FixedCost is declared over 12 elements but has only 7 values.  Use "print FixedCost;" to see what you declared.  I think you instead want two different sets of fixed cost parameters: one for Factories and one for Crossdocks.
  3. The Y variable appears only in the objective and not in any of the constraints.  In that case, the presolver will just set Y = 0.  As in issue #2, I think you want two different sets of fixed cost variables.
Occasional Contributor
Posts: 6

Re: Proc Optmodel Error in sum statement

I have created 2 sets of fixed costs, T and Y.

Still T and Y do not appear in my constraints.

Should they appear? If Yes, how?

Thanks

 

proc optmodel;

set Factories= {'Kansas','NorthCarolina','NewHampshire','SouthDakota'};
set DCs= {'Virginia','Missouri','California','Florida'};
set Crossdocks= {'Wisconsin','Minnesota', 'SouthCarolina'};

number incost{Factories,Crossdocks}=[
36 26 31
43 28 48
37 44 42
32 28 30
];

number outcost {Crossdocks,DCs}=[
37 29 15 26
30 42 40 20
16 27 46 42
];

number capacity {Factories}=[
37 19 42 25];

number demand {DCs}=[
3 12 15 15];

number ProdCost {Factories} = [500 220 200 180];
number FixedCost {Crossdocks} = [650 950 800];
number MaxUse {Crossdocks} = [37 43 31];

var inflow {Factories,Crossdocks} >= 0;
var outflow {Crossdocks,DCs} >= 0;
var T {Factories} binary;
var Y {Crossdocks} binary;

minimize TotalCost =sum {j in Crossdocks} ( sum {i in Factories} ( inflow[i,j]*incost[i,j] + Y[j]*FixedCost[j]+T[i]*ProdCost[i] )+sum {j in Crossdocks,k in DCs} outcost[j,k]*outflow[j,k]);

con Max_Supply {i in Factories} : sum {j in Crossdocks} inflow[i,j] <=capacity[i];
con No_Stock {j in Crossdocks} : sum {i in Factories} inflow[i,j] = sum {k in DCs} outflow[j,k];
con Min_Demand {k in DCs} : sum {j in Crossdocks} outflow[j,k] >=demand[k];
con Max_Use{j in Crossdocks} : sum {i in Factories} inflow[i,j] <=MaxUse[j];


solve;
print inflow outflow TotalCost;
quit;

Occasional Contributor
Posts: 6

Re: Proc Optmodel Error in sum statement

Here, I have created 2 sets of fixed costs, and also 2 constraints with number M.

 

This code runs OK, but is it correct?

Thanks for your input.

 

proc optmodel;

set Factories= {'Kansas','NorthCarolina','NewHampshire','SouthDakota'};
set DCs= {'Virginia','Missouri','California','Florida'};
set Crossdocks= {'Wisconsin','Minnesota', 'SouthCarolina'};

number incost{Factories,Crossdocks}=[
36 26 31
43 28 48
37 44 42
32 28 30
];

number outcost {Crossdocks,DCs}=[
37 29 15 26
30 42 40 20
16 27 46 42
];

number capacity {Factories}=[
37 19 42 25];

number demand {DCs}=[
3 12 15 15];

number ProdCost {Factories} = [500 220 200 180];
number FixedCost {Crossdocks} = [650 950 800];
number MaxUse {Crossdocks} = [37 43 31];
number M=1000000;

var inflow {Factories,Crossdocks} >= 0;
var outflow {Crossdocks,DCs} >= 0;
var T {Factories} binary;
var Y {Crossdocks} binary;

minimize TotalCost =sum {j in Crossdocks} ( sum {i in Factories} ( inflow[i,j]*incost[i,j] + Y[j]*FixedCost[j]+T[i]*ProdCost[i] )+sum {k in DCs} outcost[j,k]*outflow[j,k]);

con Max_Supply {i in Factories} : sum {j in Crossdocks} inflow[i,j] <=capacity[i];
con No_Stock {j in Crossdocks} : sum {i in Factories} inflow[i,j] = sum {k in DCs} outflow[j,k];
con Min_Demand {k in DCs} : sum {j in Crossdocks} outflow[j,k] >=demand[k];
con Max_Use{j in Crossdocks} : sum {i in Factories} inflow[i,j] <=MaxUse[j];
con Inspections {j in Crossdocks} : sum {i in Factories} inflow[i,j] <= M*Y[j];
con Facost {i in Factories}: sum {j in Crossdocks}inflow[i,j]<= M*T[i];

solve;
print inflow outflow TotalCost;
quit;
SAS Employee
Posts: 448

Re: Proc Optmodel Error in sum statement

Yes, that is the right idea.  But you do not need (and should not use) a large value for M, which can cause numerical difficulties.  Instead, you can avoid introducing M and the new constraints by modifying the existing Max_Supply and Max_Use constraints.  In that case, capacity[i] and MaxUse[j] will play the roles of M.

Ask a Question
Discussion stats
  • 7 replies
  • 279 views
  • 0 likes
  • 3 in conversation