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

Proc optmodel solving with likelihood maximum

Accepted Solution Solved
Reply
Highlighted
Occasional Contributor
Posts: 6
Accepted Solution

Proc optmodel solving with likelihood maximum

Hi everyone, 

I am writing to you in hoping that someone would be able to help me. I am new in proc optmodel so i had really take time to learn the basic in
proc optmodel language before starting to solve my problem.
So, I am trying to solve a quadratic problem ( in 9.4 sas version ) with a minimizing function that is based of a
likelihood maximum formulation. In that way I have two tables :tableau 1 that contains my real X (188 rows and 8836 columns) and Marges that contains my real Y (188 rows, 188 columns).

What I want is that estimates X and Y that respond to this function like for each row (i) of the two tables (that means for X and Y ) we have
min f = [(X(to estimate) - X( real in "tableau"))**2/X(real)] + [(Y(to estimate) - Y(real in "Marges"))**2 / Y(real)]
following to the constraint that the sum of X - Y = 0 ( for each rows of the two tables ).

In my code the programm runs until the reading data step, there is no syntax error and it gives me the right format of my data but when i run the code with resolving part
I have the note : "out of memory" and it stopped. I've already changed my size of sas with (memsize 0) but when i re-run it is always in "out of memory".
Actually, my problem is that i really don't know if the problem is really the memory or if it's my syntax code wich that is not good.
So if you see the code below : do you think that the problem is that my code is not correct ?
Thanks for advance for the answer and hope that the question is clear (forgive about my english)
proc optmodel; 
		
	/* I Tableau des M reels 										 */ 
	/*************************************************************/
			/* declaration de paramètre */ 
			set zone1 = 1..8836; 
			set <num> C1; 
			number trafic1{C1, zone1};

			/* Lecture de la table */ 
			read data Tableau1 into 
				C1 = [_N_] 
				{r in zone1} < trafic1[_N_, r]=col("Z"||r) >;
			print trafic1; 

	/* II Tableau des contraintes réels ==> Y réels						*/
	/*********************************************************************/
			set Cont1 = 1..188; 
			set <num> N1; 
			number Marge1{N1, Cont1};

			/* Lecture de la table */
			read data Marges into 
				N1 = [_N_] 
				{m in Cont1} < Marge1[_N_, m]=col("O"||m) >;
			print Marge1; 

	/* V Resolution  												*/ 
	/*********************************************************************/
		/* V-1) Déclaration de variables */ 
		var  x{i in C1, d in zone1} >= 0 ;
		var  y{j in N1, o in cont1} >= 0 ;
	

		/* V-2) La fonction objective : minimisation de la variance */ 
		minimize f = sum{i in C1, d in zone1} ((X[i, d] - trafic1[i, d])**2/trafic1[i, d]) +
					 sum{j in N1 , o in cont1} (( Y[j, o]- Marge1[j, o])**2/Marge1[j, o]);


		/* V-3) subject to the following constraints */
		Con Bornes {i in C1, d in zone1, j in N1, o in cont1} :(X[i, d] - Y[j, o]) = 0;

	solve;

	print {i in C1, d in zone1: X[i, d] > 0} X ;
	
quit;


 


Accepted Solutions
Solution
‎08-31-2017 12:40 PM
SAS Employee
Posts: 454

Re: Proc optmodel solving with likelihood maximum

It looks like you have some data issues (missing values and mixture of Z and VAR column names), but I think I see what you are trying to do.  You wanted 188 constraints, but you declared 188*8836*188*188 = 58.7 billion constraints instead.  Try this:

Con Bornes {i in C1}: sum {d in zone1} X[i, d] = sum {o in cont1} Y[i, o];

A good way to make sure your model is correct is to use the EXPAND statement on a smaller instance.

View solution in original post


All Replies
SAS Employee
Posts: 454

Re: Proc optmodel solving with likelihood maximum

Can you please share the data?

Occasional Contributor
Posts: 6

Re: Proc optmodel solving with likelihood maximum

Thanks for replying . I have attached two files ("tableau" ( "marges"). 

 

Attachment
SAS Employee
Posts: 454

Re: Proc optmodel solving with likelihood maximum

I see only one attachment (marges.csv).

Occasional Contributor
Posts: 6

Re: Proc optmodel solving with likelihood maximum

Here are the dataset compressed. I think it would be more accorded to my code posted before for understanding. 

 

Attachment
Occasional Contributor
Posts: 6

Re: Proc optmodel solving with likelihood maximum

I have attached two reduced files because the orginals are too bigs. So instead of having (188 row, 8836 colums for tableau1 ) and (188 rows, 188 for marges), i send you (12 rows, 12 colums for tableau1 ) and (12 rows, 12 colums for marges).

Thanks

Attachment
Attachment
SAS Employee
Posts: 454

Re: Proc optmodel solving with likelihood maximum

This smaller instance solves instantly but yields a constant optimal solution with all variables equal to 0.010473.  I suspect that your Bornes constraint is not really what you want.  Your text description mentioned a sum, but that constraint does not contain any sum.

Occasional Contributor
Posts: 6

Re: Proc optmodel solving with likelihood maximum

First I think i gave you a wrong reduced dataset for tableau1_set because  for C1 = 1..12, I should give you a dataset with 12 rows and 144 columns (+C1).  I don't know if there is a consequences for the resolution . Anyway I compressed the originals dataset ( that is attached with this mail ), i think it is better because of my error is about the note : "out of memory" that we would not see with the smaller contains. 

 

About the constraint, in the orginal dataset, what i want for contraints is that 

   if tableau1 have 188 rows and 8836 columns 

   if marges have 188 rows and 188 columns 

 

      Constraint 1 :  (X1+....+X8836) - ( Y1+....+Y188)   =0; (row 1)

       Constraint 2 :  (X1+....+X8836) - ( Y1+....+Y188)   =0; (row1)

 

         .....

      Constraint 188 : (X1+....+X8836) - ( Y1+....+Y188)   =0; (row188)

 

So i write the code like that Bornes {i in C1, d in zone1, j in N1, o in cont1} Smiley SadX[i, d] - Y[j, o]) = 0;

because i just want him to make sum operation for each row from row 1 to row 188. I don't know what exactly he does with this code. 

 

Attachment
Solution
‎08-31-2017 12:40 PM
SAS Employee
Posts: 454

Re: Proc optmodel solving with likelihood maximum

It looks like you have some data issues (missing values and mixture of Z and VAR column names), but I think I see what you are trying to do.  You wanted 188 constraints, but you declared 188*8836*188*188 = 58.7 billion constraints instead.  Try this:

Con Bornes {i in C1}: sum {d in zone1} X[i, d] = sum {o in cont1} Y[i, o];

A good way to make sure your model is correct is to use the EXPAND statement on a smaller instance.

Occasional Contributor
Posts: 6

Re: Proc optmodel solving with likelihood maximum

Thank you for your answer ! 

 

You understood very well what i wanted to do with the constraint. It was exactly what I wanted, i didn't know about the expand statement and I see it is  a very good way to look after the code. So this morning i tried with your correction of the syntax (with expand) and I see that it write exactly the model and it solves very quickly so thank you very much beacause it helped me very well. 

However, I see that the solutions is not very good but I think it is more in my model than in the code sas. Also , I see a note that sas changed the solver to NLP instead of QP so I'm gonna take a look at my model if it very optimal.

I also want to tell you that with the originals dataset, when I run the program I still needed to change the memsize to 0 then it solves in 19 second ( better with 188 constraint of course Smiley Happy ) . 

 

Thank you again and I'll come back to you this evening if I find that it is my model wich us not goog or the QP solver is not adapted. 

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 302 views
  • 1 like
  • 2 in conversation