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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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