Having trouble with defining a constraint for optimization model:
- keeps 'sum' - 'sum' not working .... ideas?
proc optmodel;
set Hor_Nodes={'1H', '2H', '3H', '4H', '5H'};
set Ver_Nodes={'1V', '2V', '3V', '4V', '5V'};
number Matrix{Ver_Nodes,Hor_Nodes}=[
0 3 4 5 0
3 0 0 0 7
4 0 0 2 4
5 0 2 0 1
0 7 4 1 0];
var x{Ver_Nodes, Hor_Nodes}>=0;
min z = sum{i in Hor_Nodes}(sum{j in Ver_Nodes}x[j,i]*Matrix[j,i]);
con Flow_const{j in Ver_Nodes}: sum{i in Hor_nodes}x[j,i] -sum{i in Ver_Nodes}x[i,j]=0;
solve;
print Matrix;
print z;
quit;
Your constraint refers to variables that don't exist, and that is why you get these error messages:
ERROR: The array subscript 'x['1V','1V']' is invalid at line 15 column 82.
ERROR: The array subscript 'x['1V','2V']' is invalid at line 15 column 82.
ERROR: The array subscript 'x['1V','3V']' is invalid at line 15 column 82.
ERROR: The array subscript 'x['1V','4V']' is invalid at line 15 column 82.
I think you might need to collapse your Hor_nodes and Ver_nodes into a single set of nodes, as in this documentation example. But if all your supplies and demands are 0, the trivial solution with x[j,i] = 0 everywhere is optimal. Maybe it would help to take a step back and describe your business problem in words without any algebra.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.