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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

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.

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