HI Alex,
Thanks a lot !!!
it is working very fine.
Regards,
Larry
Este mensaje y sus archivos adjuntos van dirigidos exclusivamente a su destinatario pudiendo contener información confidencial. No está permitida su reproducción o distribución sin la autorización expresa de la Universidad Sergio Arboleda, sedes o seccionales. Si usted no es el destinatario final por favor elimínelo e informemos por esta vía. El presente correo electrónico solo refleja la opinión de su remitente y no representa necesariamente la opinión oficial de la Universidad Sergio Arboleda, sedes o seccionales o de sus Directivos. Puede usted ejercitar los derechos de consulta, tratamiento, actualización, corrección o supresión sobre sus datos, mediante escrito dirigido a Universidad Sergio Arboleda, a través de correo electrónico en la dirección habeas.data@usa.edu.co, indicando en la línea de asunto el derecho que desea ejercitar, o mediante correo ordinario remitido a la Calle 74 No. 14-14 Bogotá D.C., Dirección Jurídica y de Contratación.
Original Message:
Sent: 6/14/2020 12:37:00 PM
From: ALEX FLEISCHER
Subject: RE: Non linear constraints
Hi,
you forgot that F and G are not functions but arrays of functions.
int n=4;
int T[i in 1..n]=i;
int TW[i in 1..n]=i;
int BP1[i in 1..n]=i;
int U[i in 1..n]=i+1;
int UW[i in 1..n]=i+1;
int BP2[i in 1..n]=i+2;
int V[i in 1..n]=i+3;
int VW[i in 1..n]=i+3;
int BP3[i in 1..n]=i+4;
int W[i in 1..n]=i+5;
int WW[i in 1..n]=i+5;
dvar float+ x[1..n];
dvar float+ Krw[1..n];
dvar float+ Kro[1..n];
// Kro Piecewise
pwlFunction F[i in 1..n] = piecewise{ T[i]->BP1[i]; U[i]->BP2[i]; V[i]->BP3[i]; W[i] };
// Krw Piecewise
pwlFunction G[i in 1..n] = piecewise{ TW[i]->BP1[i]; UW[i]->BP2[i]; VW[i]->BP3[i]; WW[i] };
//with the following constraint:
subject to {
forall(i in 1..n){
SetofConst7: Krw[i] <= G[i](x[i]);
SetofConst8: Kro[i] <= F[i](x[i]);
}
}
works fine
regards
------------------------------
ALEX FLEISCHER
------------------------------
Original Message:
Sent: Sat June 13, 2020 11:20 PM
From: Larry Prentt
Subject: Non linear constraints
Alex thank you.
I defined this array:
dvar float+ x[1..n];
// Kro Piecewise
pwlFunction F[i in 1..n] = piecewise{ T[i]->BP1[i]; U[i]->BP2[i]; V[i]->BP3[i]; W[i] };
// Krw Piecewise
pwlFunction G[i in 1..n] = piecewise{ TW[i]->BP1[i]; UW[i]->BP2[i]; VW[i]->BP3[i]; WW[i] };
with the following constraint:
subject to {
..........
...........
forall(i in 1..n){
SetofConst7: Krw[i] <= G(x[i]);
SetofConst8: Kro[i] <= F(x[i]);
}
}
I obtained the following error in CPLEX:
Cannot use type pwlFunction[range] for userFunction.
How Can I handle this ?
Regards,
Larry
Este mensaje y sus archivos adjuntos van dirigidos exclusivamente a su destinatario pudiendo contener información confidencial. No está permitida su reproducción o distribución sin la autorización expresa de la Universidad Sergio Arboleda, sedes o seccionales. Si usted no es el destinatario final por favor elimínelo e informemos por esta vía. El presente correo electrónico solo refleja la opinión de su remitente y no representa necesariamente la opinión oficial de la Universidad Sergio Arboleda, sedes o seccionales o de sus Directivos. Puede usted ejercitar los derechos de consulta, tratamiento, actualización, corrección o supresión sobre sus datos, mediante escrito dirigido a Universidad Sergio Arboleda, a través de correo electrónico en la dirección habeas.data@usa.edu.co, indicando en la línea de asunto el derecho que desea ejercitar, o mediante correo ordinario remitido a la Calle 74 No. 14-14 Bogotá D.C., Dirección Jurídica y de Contratación.
Original Message:
Sent: 6/9/2020 5:21:00 PM
From: ALEX FLEISCHER
Subject: RE: Non linear constraints
Yes:
int nbKids=300; float costBus40=500; float costBus30=400; // If we take more than 4 buses for a given size, 20% cheaper for additional buses dvar int+ nbBus40; dvar int+ nbBus30; range pricingRule=1..2; pwlFunction pricePerQuantity[i in pricingRule]= piecewise{1->4;(i==1)?0.8:0.9}; assert forall(r in pricingRule,k in 1..4 ) pricePerQuantity[r](k)==k; assert forall(k in 5..10) as:abs(pricePerQuantity[1](k)-4-(k-4)*0.8)<=0.00001; assert forall(k in 5..10) as2:abs(pricePerQuantity[2](k)-4-(k-4)*0.9)<=0.00001; int rule=1; minimize costBus40*pricePerQuantity[rule](nbBus40) +pricePerQuantity[rule](nbBus30)*costBus30; subject to { 40*nbBus40+nbBus30*30>=nbKids; }
------------------------------
ALEX FLEISCHER
Original Message:
Sent: Tue June 09, 2020 04:05 PM
From: Larry Prentt
Subject: Non linear constraints
Hi Alex,
Thank you very much for this option.
other question: is it possible to implement arrays of piecewise using the ternary operator ?
regards,
Larry
Este mensaje y sus archivos adjuntos van dirigidos exclusivamente a su destinatario pudiendo contener información confidencial. No está permitida su reproducción o distribución sin la autorización expresa de la Universidad Sergio Arboleda, sedes o seccionales. Si usted no es el destinatario final por favor elimínelo e informemos por esta vía. El presente correo electrónico solo refleja la opinión de su remitente y no representa necesariamente la opinión oficial de la Universidad Sergio Arboleda, sedes o seccionales o de sus Directivos. Puede usted ejercitar los derechos de consulta, tratamiento, actualización, corrección o supresión sobre sus datos, mediante escrito dirigido a Universidad Sergio Arboleda, a través de correo electrónico en la dirección habeas.data@usa.edu.co, indicando en la línea de asunto el derecho que desea ejercitar, o mediante correo ordinario remitido a la Calle 74 No. 14-14 Bogotá D.C., Dirección Jurídica y de Contratación.
Original Message:
Sent: 6/5/2020 4:04:00 AM
From: ALEX FLEISCHER
Subject: RE: Non linear constraints
Hi,
you can use arrays of piecewise.
Let me change a bit the zoo piecewise from https://www.linkedin.com/pulse/making-decision-optimization-simple-alex-fleischer/
int nbKids=300; float costBus40=500; float costBus30=400; // If we take more than 4 buses for a given size, 20% cheaper for additional buses dvar int+ nbBus40; dvar int+ nbBus30; range pricingRule=1..2; pwlFunction pricePerQuantity[pricingRule]=[piecewise{1->4;0.8},piecewise{1->4;0.9}]; assert forall(r in pricingRule,k in 1..4 ) pricePerQuantity[r](k)==k; assert forall(k in 5..10) as:abs(pricePerQuantity[1](k)-4-(k-4)*0.8)<=0.00001; assert forall(k in 5..10) as2:abs(pricePerQuantity[2](k)-4-(k-4)*0.9)<=0.00001; int rule=1; minimize costBus40*pricePerQuantity[rule](nbBus40) +pricePerQuantity[rule](nbBus30)*costBus30; subject to { 40*nbBus40+nbBus30*30>=nbKids; }
------------------------------
ALEX FLEISCHER
Original Message:
Sent: Thu June 04, 2020 11:06 PM
From: Larry Prentt
Subject: Non linear constraints
Hi Alex,
I used the your code example with the function x^4-log(x) when you reply to sandeepsinghchauhan in July-2017 as follows with my function:
////////
float firstSlope=0;
float lastSlope=0;
tuple breakpoint // y=f(x)
{
key float x;
float y;
}
sorted { breakpoint } breakpoints={<i/100,Krwep*pow(i/100,Nw)> | i in 1..100};
float slopesBeforeBreakpoint[b in breakpoints]=
(b.x==first(breakpoints).x)
?firstSlope
:(b.y-prev(breakpoints,b).y)/(b.x-prev(breakpoints,b).x);
pwlFunction f=piecewise(b in breakpoints)
{ slopesBeforeBreakpoint[b]->b.x; lastSlope } (first(breakpoints).x, first(breakpoints).y);
dvar float x in 0.01..1;
/////////
Is it possible to implement x as vector into the piecewise function?
I have four layers and I am calculating production from layers and the idea is to obtain differents values of x per layer.
Thank you very much.
Regards,
Larry
Este mensaje y sus archivos adjuntos van dirigidos exclusivamente a su destinatario pudiendo contener información confidencial. No está permitida su reproducción o distribución sin la autorización expresa de la Universidad Sergio Arboleda, sedes o seccionales. Si usted no es el destinatario final por favor elimínelo e informemos por esta vía. El presente correo electrónico solo refleja la opinión de su remitente y no representa necesariamente la opinión oficial de la Universidad Sergio Arboleda, sedes o seccionales o de sus Directivos. Puede usted ejercitar los derechos de consulta, tratamiento, actualización, corrección o supresión sobre sus datos, mediante escrito dirigido a Universidad Sergio Arboleda, a través de correo electrónico en la dirección habeas.data@usa.edu.co, indicando en la línea de asunto el derecho que desea ejercitar, o mediante correo ordinario remitido a la Calle 74 No. 14-14 Bogotá D.C., Dirección Jurídica y de Contratación.
Original Message:
Sent: 6/3/2020 2:43:00 AM
From: ALEX FLEISCHER
Subject: RE: Non linear constraints
Hi
example with points:
/* OPL supports piecewise linear functions, which are important in many applications. In most cases, you specify piecewise linear functions by giving a set of slopes, a set of breakpoints at which the slopes change, and the value of the functions at a given point. The parameters are n breakpoints and n+1 slopes, and s -> b means that the slope s goes up to breakpoint b. But some find this a bit hard and prefer to enter sets of (x,y), so let me help them through an example: */ //pwl1: y = x 0.5 (0, 0) (1, 1) (2, 4) 2.0 float firstSlope=0.5; float lastSlope=2.0; tuple breakpoint // y=f(x) { key float x; float y; } sorted { breakpoint } breakpoints={<0,0>,<1,1>,<2,4>}; float slopesBeforeBreakpoint[b in breakpoints]= (b.x==first(breakpoints).x) ?firstSlope :(b.y-prev(breakpoints,b).y)/(b.x-prev(breakpoints,b).x); pwlFunction f=piecewise(b in breakpoints) { slopesBeforeBreakpoint[b]->b.x; lastSlope } (first(breakpoints).x, first(breakpoints).y); assert forall(b in breakpoints) f(b.x)==b.y;
regards
------------------------------
ALEX FLEISCHER
Original Message:
Sent: Tue June 02, 2020 12:26 PM
From: Larry Prentt
Subject: Non linear constraints
Hi Alex,
Thank you.
Please send me a link or reference to work with breakpoints,
Best regards
Larry
Este mensaje y sus archivos adjuntos van dirigidos exclusivamente a su destinatario pudiendo contener información confidencial. No está permitida su reproducción o distribución sin la autorización expresa de la Universidad Sergio Arboleda, sedes o seccionales. Si usted no es el destinatario final por favor elimínelo e informemos por esta vía. El presente correo electrónico solo refleja la opinión de su remitente y no representa necesariamente la opinión oficial de la Universidad Sergio Arboleda, sedes o seccionales o de sus Directivos. Puede usted ejercitar los derechos de consulta, tratamiento, actualización, corrección o supresión sobre sus datos, mediante escrito dirigido a Universidad Sergio Arboleda, a través de correo electrónico en la dirección habeas.data@usa.edu.co, indicando en la línea de asunto el derecho que desea ejercitar, o mediante correo ordinario remitido a la Calle 74 No. 14-14 Bogotá D.C., Dirección Jurídica y de Contratación.
Original Message:
Sent: 6/2/2020 11:55:00 AM
From: ALEX FLEISCHER
Subject: RE: Non linear constraints
Hi,
then if you want to use piecewise in
https://www.linkedin.com/pulse/how-opl-alex-fleischer/
you have How to describe a piecewise linear function with breakpoints instead of slopes ?
regards
------------------------------
ALEX FLEISCHER
Original Message:
Sent: Tue June 02, 2020 11:44 AM
From: Larry Prentt
Subject: Non linear constraints
Daniel
Thank you very much. Nw and No have values between 1 and 5 as float
I will be implementing the piecewise linear
Best regards,
Larry
Este mensaje y sus archivos adjuntos van dirigidos exclusivamente a su destinatario pudiendo contener información confidencial. No está permitida su reproducción o distribución sin la autorización expresa de la Universidad Sergio Arboleda, sedes o seccionales. Si usted no es el destinatario final por favor elimínelo e informemos por esta vía. El presente correo electrónico solo refleja la opinión de su remitente y no representa necesariamente la opinión oficial de la Universidad Sergio Arboleda, sedes o seccionales o de sus Directivos. Puede usted ejercitar los derechos de consulta, tratamiento, actualización, corrección o supresión sobre sus datos, mediante escrito dirigido a Universidad Sergio Arboleda, a través de correo electrónico en la dirección habeas.data@usa.edu.co, indicando en la línea de asunto el derecho que desea ejercitar, o mediante correo ordinario remitido a la Calle 74 No. 14-14 Bogotá D.C., Dirección Jurídica y de Contratación.
Original Message:
Sent: 6/2/2020 3:56:00 AM
From: Daniel Junglas
Subject: RE: Non linear constraints
With the CPLEX solver engine, the only exponents allowed for decision variables are 1 and 2. If Nw is anything else then this is not supported and you will have to reformulate your objective (for example use a piecewise linear). If Nw happens to be 2 then try to write this explicitly as quadratic term.
------------------------------
Daniel Junglas
Original Message:
Sent: Mon June 01, 2020 01:33 PM
From: Larry Prentt
Subject: Non linear constraints
Good Morning
I am tryng to implement the following nonlinear constraint:
forall(i in N){ forall(i in N){ SetofConst8: Krw[i] == Krwep*pow(Swn[i],Nw); SetofConst9: Kro[i] == Kroep*pow((1-Swn[i]),No); }
the error message is : TypeFunction pow(dvar float+,float) not available in context CPLEX.
Attached the complete .mod file
Thank you for your attention and help
Best regards,
Larry
/*********************************************/********************************************* * OPL 12.10.0.0 Model * Author: Lprentt * Creation Date: Jun 1, 2020 at 8:39:14 AM *********************************************/ // data declaration int n = ...; // number of Layers float re = ...; // Radio del yacimiento o del area de drenaje float rw = ...; // Radio del pozo range N = 1..n; // variable declaration dvar float+ Qw[N]; // Tasas de agua por capadvar float+ Qo[N]; // Tasas de petroleo por capa
dvar float+ Swn[N]; // Saturacion de agua por capa
dvar float Krw[N]; // Tasas de petroleo por capadvar float Kro[N]; // Tasas de petroleo por capa
float K[N]= ...; // Permeabilidad absoluta por capafloat h[N]= ...; // Espesor neto petrolifero por capafloat Uw[N]= ...; // Viscosidad del agua por capafloat Uo[N]= ...; // Viscosidad del petroleo por capafloat S[N]= ...; // Skin o factor de daño por capafloat Pyac[N]= ...; // Presion promedio de yacimiento por capafloat Pwf[N]= ...; // Presion de fondo fluyendo por capa
float Qws= ...; // Tasa Total de agua en superficiefloat Qos= ...; // Tasa Total de Petroleo en superficie
float Krwep= ...; //float Kroep= ...; //
float Nw= ...; //float No= ...; //
float Bwi= ...; // Factor Volumetrico del aguafloat Boi= ...; // Factor Volumetrico del petroleo
float Fw;
execute { Fw = (Qws/Qos)/((Qws/Qos)+Boi/Bwi);}
// objective function maximize Fw*sum(i in N)Qo[i] - (1-Fw)*sum(i in N)Qw[i]; // constraints subject to { forall(i in N){ SetofConst1: Qo[i] == 0.00708*K[i]*Kro[i]*h[i]*(Pyac[i]-Pwf[i])/(Uo[i]*(ln(re/rw)-0.75+S[i])); // } forall(i in N){ SetofConst2: Qw[i] == 0.00708*K[i]*Krw[i]*h[i]*(Pyac[i]-Pwf[i])/(Uw[i]*(ln(re/rw)-0.75+S[i])); // } forall(i in N){ SetofConst3: 0.0 <= Swn[i] <= 1; SetofConst4: 0.001 <= Krw[i] <= 0.1; SetofConst5: 0.001 <= Kro[i] <= 0.7; }
SetofConst6: sum(i in N)Qo[i] == Qos*Boi; SetofConst7: sum(i in N)Qw[i] == Qws*Bwi;
forall(i in N){// here the error SetofConst8: Krw[i] == Krwep*pow(Swn[i],Nw); SetofConst9: Kro[i] == Kroep*pow((1-Swn[i]),No); } }
------------------------------
Larry Prentt
------------------------------
#DecisionOptimization