BookmarkSubscribeRSS Feed
indi5000
Calcite | Level 5

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;
1 REPLY 1
RobPratt
SAS Super FREQ

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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Discussion stats
  • 1 reply
  • 1350 views
  • 0 likes
  • 2 in conversation