## Conditional Constarint in proc optmodel

``````/* II-  PROGRAME OPTMODEL 															*/
/***********************************************************************************/
proc optmodel;

/* 0 Tableau des chemins & Marges								*/
/************************************************************/
/* declaration de paramètre 	*/

Set <string> Vecteur_&Typej._&Heure._&Annee.;
Set <string> Marge_&Typej._&Heure._&Annee.;
num Tij{Vecteur_&Typej._&Heure._&Annee.};

num marges{Marge_&Typej._&Heure._&Annee.};
num STDMarges{Marge_&Typej._&Heure._&Annee.};
num Nobs{Marge_&Typej._&Heure._&Annee.};
num chemin{Vecteur_&Typej._&Heure._&Annee., Marge_&Typej._&Heure._&Annee.};

/******************************************************************/

Vecteur_&Typej._&Heure._&Annee. = [Vecteur] Tij;
print Tij;

Marge_&Typej._&Heure._&Annee. = [N]
marges = marges
STDMarges = STDMarges
NObs = Nobs
{p in Vecteur_&Typej._&Heure._&Annee.} <chemin[p,N]= col(p)>;
print  marges STDMarges Nobs chemin;

/* III Resolution  												*/
/*********************************************************************/
/* V-1) Déclaration de variables */

var  X{Vecteur_&Typej._&Heure._&Annee.} >= 0;
Var  Y{Marge_&Typej._&Heure._&Annee.} >= 0 ;

/* V-2) La fonction objective : minimisation de la variance */

minimize f = sum{p in Vecteur_&Typej._&Heure._&Annee.} (X[p]-Tij[p])**2/(Tij[p]/3)**2 + sum{r in Marge_&Typej._&Heure._&Annee.} ((Y[r]- Marges[r])**2/(STDMarges[r]**2/Nobs[r]));

/* V-3) subject to the following constraints */

Con Bornes{r in Marge_&Typej._&Heure._&Annee.}: sum{p in Vecteur_&Typej._&Heure._&Annee.} chemin[p, r]*X[p] = Y[r];

/* Con Condtion1{r in Marge_&Typej._&Heure._&Annee. :}: If r = 17 then sum{p in Vecteur_&Typej._&Heure._&Annee.} chemin[p, r]*X[p] > 0;
Con Condtion1{r in Marge_&Typej._&Heure._&Annee. :}: If r = 16 then sum{p in Vecteur_&Typej._&Heure._&Annee.} chemin[p, r]*X[p] > 0;*/

solve ;
print X;
Print Y;

create data Vecteur_est_&Typej._&Heure._&Annee. from [p] Tij&Annee. = X ;
create data Marge_est_&Typej._&Heure._&Annee. from [r]  Marges&Annee. = Y ;
``````

Good morning,

I want to make conditions in my constraint because in the solutions of X and Y, I need some sum in the line of Y like :

1) In the first solution Y: (Marge_est_&Typel.&Heure._&Annee. ) with Y[r]

==> I need that  Y = Y +Y   with Y#0 and Y #0

(there is some case like those lines but not all the line in the table, it is a transportation problem..)

and in the same time

2) I have the constraint that the sum in line of  X[1...52]*chemin[52, 31]  is equal at the sum of Y[1..31]

for example : for the first line of Y   : [1...52]*chemin[1..52, 1] = Y ; I have no problem to write this second constraint "con" like in the code I sent here in Pj.

==>The origin of this problem is that in my  real data set in the table   Marge_&Typel.&Heure._&Annee.  :

the line 17 = 0 , the line 18 = 0 so the QP affect s100% of Y in just one of Y or Y

==>So I thought that the solutions were : making  some condition contraint to estimates line in this case to have in the estimation not Y =  Y  +0        with Y = 0

but Y  = Y +Y   with Y #0 and Y #0

@RobPratt

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: Conditional Constarint in proc optmodel

If I understand correctly, you should include the following two additional statements:

``````   con YSum: Y['N16'] = Y['N17'] + Y['N18'];
for {r in /N17 N18/} Y[r].lb = 1e-3;
``````

The first statement declares your new constraint, and the second statement changes the lower bounds on Y['N17'] and Y['N18'] from 0 to 1e-3.  Here, 1e-3 is just an example.  You have to decide for yourself how large Y[r] must be for you to consider it to be positive.

2 REPLIES 2

## Re: Conditional Constarint in proc optmodel

If I understand correctly, you should include the following two additional statements:

``````   con YSum: Y['N16'] = Y['N17'] + Y['N18'];
for {r in /N17 N18/} Y[r].lb = 1e-3;
``````

The first statement declares your new constraint, and the second statement changes the lower bounds on Y['N17'] and Y['N18'] from 0 to 1e-3.  Here, 1e-3 is just an example.  You have to decide for yourself how large Y[r] must be for you to consider it to be positive.

## Re: Conditional Constarint in proc optmodel

Thank you for your response ! It gives me the syntax for a condition but I think that I need changing something in my resolution programm.

Discussion stats
• 2 replies
• 864 views
• 0 likes
• 2 in conversation