Topic
• 23 replies
• Latest Post - ‏2017-03-29T11:36:50Z by AlexFleischer
waterstyler
2 Posts

# Pinned topic except some value

‏2013-06-20T02:01:02Z | exception

Hello

forall(i in Facility EXCEPT WHEN i EQUAL ALPHA,j in Facility,t in Time)Except:L[i][j][t]==0;

Is there any way to code this constraint. Thank you in advance

• AlexFleischer
3277 Posts

#### Re: except some value

‏2013-06-24T07:48:37Z

Hi

have you tried

forall(i in Facility ,j in Facility,t in Time: i!=ALPHA)Except:L[i][j][t]==0;

regards

• VYSN_Kai_Kühnel
17 Posts

#### Re: except some value

‏2017-03-14T12:58:24Z

Hi

have you tried

forall(i in Facility ,j in Facility,t in Time: i!=ALPHA)Except:L[i][j][t]==0;

regards

Hi Alex,

I have kind of the same problem with a inventory balance constraint.
I used this:

```ctBatteriebilanz1[1]:
z[1] == 0.9 + (sum(j in J)x[j][1])/Q - sum(j in J) (d[j][1]*y[j][1]) - r[1]*q[1] - f[1];
```
```forall (t in T: t!=1) ctBatteriebilanz[t]:
//z[t] == z[t-1] + (((PL*exp(s*((z[t-1]/Q)/kL)*100))/K * sum(j in J)x[j][t]*nL)/Q) - sum(j in J) (d[j][t]*y[j][t]) - r[t]*q[t] - f[t];
z[t] == z[t-1] + (sum(j in J)x[j][t])/Q - sum(j in J) (d[j][t]*y[j][t]) - r[t]*q[t] - f[t];
```

Because t = 0 is not working with the problem. I used your advice to implement t!=1 to solve that problem. But still it says:" The index of the Array is out of allowed range: 0."

What is the problem?

Data:

``` J = {1,2,3,4};
T = {1,2,3,4};
N = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};

c = [0.2,0.5,0.3,1.0];
//w = [70,20,40,100];
o = [200,10,0,100];
A = [3,5,3,1]; //    Vielleicht unnötig
a = [[3,4,0,0],[1,3,3,0],[1,1,1,1],[0,0,0,0]]; // Vielleicht unnötig
f = [20,30,10,90]; //    Fahrzeit der Kundenfahrt in Periode t in [min]
r = [10,5,4,13]; //    Fahrzeit von Kunden-Drop-off bis zum nächsten Kunden-Pick-up ohne einen Ladestop in Periode t in [min]
g = [0.000001,0.000001,0.000001,0.000001]; //    Kosten der Wartezeit an Ladestation j in [€]
p = [50,100,20,30]; //    Geforderter Abholzeitpunkt des Kunden am Ende der Periode t um den Kunden in t+1 zu befördern in [min]
//d = []; // Fahrzeit zur Ladestation j und zum nächsten Kunden-Pick-up Ort in Periode t
d1 = [[10,4,20,10],[2,45,1,23],[1,2,3,4,][20,10,30,12]]; // Fahrzeit zur Ladestation j in Periode t
d2 = [[5,12,13,3],[1,2,1,2],[10,10,10,10],[10,20,23,12]]; // Fahrzeit von Ladestation j zu Kunden-Pick-up Oprt in Periode t
//b = []; // Belegung der Ladestation j durch andere Taxis zur Minute n
K = 24; //       Maximale Batteriekapazität des Taxi´s in [KWh]
Q = 300; //       Maximale Fahrzeit mit voller Batterie in [min]
M = 100000000000000; //       Große Zahl
b = [[1,0,0,1,1,1,1,0,0,0],[0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,1],[0,0,0,0,0,1,1,1,1,1]];
```

• AlexFleischer
3277 Posts

#### Re: except some value

‏2017-03-14T13:16:16Z

Hi Alex,

I have kind of the same problem with a inventory balance constraint.
I used this:

<pre dir="ltr">ctBatteriebilanz1[1]: z[1] == 0.9 + (sum(j in J)x[j][1])/Q - sum(j in J) (d[j][1]*y[j][1]) - r[1]*q[1] - f[1]; </pre> <pre dir="ltr">forall (t in T: t!=1) ctBatteriebilanz[t]: //z[t] == z[t-1] + (((PL*exp(s*((z[t-1]/Q)/kL)*100))/K * sum(j in J)x[j][t]*nL)/Q) - sum(j in J) (d[j][t]*y[j][t]) - r[t]*q[t] - f[t]; z[t] == z[t-1] + (sum(j in J)x[j][t])/Q - sum(j in J) (d[j][t]*y[j][t]) - r[t]*q[t] - f[t]; </pre>

Because t = 0 is not working with the problem. I used your advice to implement t!=1 to solve that problem. But still it says:" The index of the Array is out of allowed range: 0."

What is the problem?

Data:

<pre dir="ltr"> J = {1,2,3,4}; T = {1,2,3,4}; N = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; c = [0.2,0.5,0.3,1.0]; //w = [70,20,40,100]; o = [200,10,0,100]; A = [3,5,3,1]; // Vielleicht unnötig a = [[3,4,0,0],[1,3,3,0],[1,1,1,1],[0,0,0,0]]; // Vielleicht unnötig f = [20,30,10,90]; // Fahrzeit der Kundenfahrt in Periode t in [min] r = [10,5,4,13]; // Fahrzeit von Kunden-Drop-off bis zum nächsten Kunden-Pick-up ohne einen Ladestop in Periode t in [min] g = [0.000001,0.000001,0.000001,0.000001]; // Kosten der Wartezeit an Ladestation j in [€] p = [50,100,20,30]; // Geforderter Abholzeitpunkt des Kunden am Ende der Periode t um den Kunden in t+1 zu befördern in [min] //d = []; // Fahrzeit zur Ladestation j und zum nächsten Kunden-Pick-up Ort in Periode t d1 = [[10,4,20,10],[2,45,1,23],[1,2,3,4,][20,10,30,12]]; // Fahrzeit zur Ladestation j in Periode t d2 = [[5,12,13,3],[1,2,1,2],[10,10,10,10],[10,20,23,12]]; // Fahrzeit von Ladestation j zu Kunden-Pick-up Oprt in Periode t //b = []; // Belegung der Ladestation j durch andere Taxis zur Minute n K = 24; // Maximale Batteriekapazität des Taxi´s in [KWh] Q = 300; // Maximale Fahrzeit mit voller Batterie in [min] M = 100000000000000; // Große Zahl b = [[1,0,0,1,1,1,1,0,0,0],[0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,1],[0,0,0,0,0,1,1,1,1,1]]; </pre>

Hi,

can you attach .mod and .dat ?

regards

• VYSN_Kai_Kühnel
17 Posts

#### Re: except some value

‏2017-03-14T13:53:24Z

Hi,

can you attach .mod and .dat ?

regards

Hi Alex,

Below you can find the .mod and .dat files.

Thank you

#### Attachments

• AlexFleischer
3277 Posts

#### Re: except some value

‏2017-03-14T14:15:21Z

Hi Alex,

Below you can find the .mod and .dat files.

Thank you

Hi,

here a version that works better.

Are you a researcher ? Or is that a business problem ?

regards

#### Attachments

• VYSN_Kai_Kühnel
17 Posts

#### Re: except some value

‏2017-03-14T14:29:50Z

Hi,

here a version that works better.

Are you a researcher ? Or is that a business problem ?

regards

I am doing my Bachelor thesis at Technical University of Munich. So it is a research work.

• VYSN_Kai_Kühnel
17 Posts

#### Re: except some value

‏2017-03-14T14:37:30Z

Hi,

here a version that works better.

Are you a researcher ? Or is that a business problem ?

regards

Thank you very much that helps a lot!

• VYSN_Kai_Kühnel
17 Posts

#### Re: except some value

‏2017-03-14T14:56:28Z

Hi,

here a version that works better.

Are you a researcher ? Or is that a business problem ?

regards

But through inserting "Using CP;" there are no values for the decision variables ...

• AlexFleischer
3277 Posts

#### Re: except some value

‏2017-03-14T15:06:56Z

But through inserting "Using CP;" there are no values for the decision variables ...

Right.

And you need to debug.

For example you have z as a dvar int but also

z[0] == 0.9;

which is not possible.

Regards

• VYSN_Kai_Kühnel
17 Posts

#### Re: except some value

‏2017-03-20T12:20:32Z

Right.

And you need to debug.

For example you have z as a dvar int but also

z[0] == 0.9;

which is not possible.

Regards

Hi,

I found a view logical errors, but still there is no value for all my decision variables... What could be the reason of this problem besides bugs in the program. Could it be a redundant constraint or because of too much decision variables. I can not find my fault.

Best regards
Kai

• AlexFleischer
3277 Posts

#### Re: except some value

‏2017-03-20T13:15:30Z

Hi,

I found a view logical errors, but still there is no value for all my decision variables... What could be the reason of this problem besides bugs in the program. Could it be a redundant constraint or because of too much decision variables. I can not find my fault.

Best regards
Kai

Hi,

you may have constraints that make your model not feasible.

What you could so is comment all of them and then add them back one by one.

regards

• VYSN_Kai_Kühnel
17 Posts

#### Re: except some value

‏2017-03-20T13:54:06Z

Hi,

you may have constraints that make your model not feasible.

What you could so is comment all of them and then add them back one by one.

regards

Yes I did that already and found the constraint which are problematic but i hoenstly dont know why :D

Regards

• AlexFleischer
3277 Posts

#### Re: except some value

‏2017-03-20T14:09:15Z

Yes I did that already and found the constraint which are problematic but i hoenstly dont know why :D

Regards

Hi,

ok so maybe you can post your simplified model so that other users could have a look.

regards

• AlexFleischer
3277 Posts

#### Re: except some value

‏2017-03-21T07:30:36Z
This reply was deleted by VYSN_Kai_Kühnel 2017-03-23T10:27:40Z.

Hi,

if you keep only

subject to {

ct1:z[0] == 6;

forall (t in T:t==1)
ct2:z[t-1]>= f[t] + sum(j in J) d1[j][t] * y[j][t] + r[t]*q[t];

}

you get a conflict between ct1 and ct2!

regards

• VYSN_Kai_Kühnel
17 Posts

#### Re: except some value

‏2017-03-21T09:59:41Z

Hi,

if you keep only

subject to {

ct1:z[0] == 6;

forall (t in T:t==1)
ct2:z[t-1]>= f[t] + sum(j in J) d1[j][t] * y[j][t] + r[t]*q[t];

}

you get a conflict between ct1 and ct2!

regards

Oh yes (t in T:t!=0) is missing! Thank you !
But still does not change the solution. But I think there is a problem with a redundant constraint...

Thanks

Kai

Updated on 2017-03-21T10:01:23Z at 2017-03-21T10:01:23Z by VYSN_Kai_Kühnel
• VYSN_Kai_Kühnel
17 Posts

#### Re: except some value

‏2017-03-24T14:41:25Z

Hi

have you tried

forall(i in Facility ,j in Facility,t in Time: i!=ALPHA)Except:L[i][j][t]==0;

regards

Hi Alex,

is it somehow possible to implement a constraint for t+1 ?:

forall(t in T)

z[t]>=  f[t+1] + sum(j in J)d1[j][t+1];

Because with "union" it somehow does not work...

Regards
Kai

• AlexFleischer
3277 Posts

#### Re: except some value

‏2017-03-24T14:52:10Z

Hi Alex,

is it somehow possible to implement a constraint for t+1 ?:

forall(t in T)

z[t]>=  f[t+1] + sum(j in J)d1[j][t+1];

Because with "union" it somehow does not work...

Regards
Kai

Hi,

why not ?

regards

• VYSN_Kai_Kühnel
17 Posts

#### Re: except some value

‏2017-03-28T12:26:41Z

Hi,

why not ?

regards

I dont know its not working well. I changed the Data and all the necessary declaration.

``` {int} J = ...;            // Set der Ladestationen j in J
//range J = 1..nbJ;
{int} T = ...;            // Set der Perioden t in T
int nbN = ...;            // Minuten (Zähler)
range N = 1..nbN;         // Set Anzahl der Minuten (Zeitraum)
{int} T0=T union {0};
{int} Tend=T union {11};

//Parameter
float c[J] = ...;         // Ladekosten des Taxi´s an Ladestation j in [€/min]
int o[J] = ...;           // Eröffnungskosten der Ladestation j in [€]
int f[Tend] = ...;           // Fahrzeit der Kundenfahrt in Periode t in [min]
int r[T] = ...;           // Fahrzeit von Kunden-Drop-off bis zum nächsten Kunden-Pick-up ohne einen Ladestop in Periode t in [min]
float g[J] = ...;         // Kosten der Wartezeit an Ladestation j in [€]
int p[T] = ...;          // Geforderter Abholzeitpunkt des Kunden am Ende der Periode t um den Kunden in t+1 zu befördern in [min]
int d[T][J] = ...;        // Fahrzeit zur Ladestation j und zum nächsten Kunden-Pick-up Ort in Periode t
int d1[Tend][J] = ...;       // Fahrzeit zur Ladestation j in Periode t
int d2[Tend][J] = ...;       // Fahrzeit von Ladestation j zu Kunden-Pick-up Oprt in Periode t
int b[J][N] = ...;        // Belegung der Ladestation j durch andere Taxis zur Minute n
int K = ...;              // Maximale Batteriekapazität des Taxi´s in [min]
int W = ...;              // Minimale Batteriekapazität des Taxi's in [min]
int p1[T]=...;

// If the data elements are organized in columns
/*
int nb1[1..nbT*nbJ*nbN] = ...;
int nbArray[t in 1..nbT, j in 1..nbJ,n in 1..nbN] = nb1[n+nbN*(j-1)+nbJ*nbN*(t-1)];

execute {
writeln(nbArray); */

// Hilfsparameter
int L=...;                 // Upper bound
int U=...;                 // Lower bound
// Erweiterung um Periode 0

dvar boolean y[T][J];      // 1, wenn Ladestation j in Periode t angefahren wird um dort zu laden, 0 sonst
dvar boolean q[T];         // 1, wenn in Periode t nicht geladen wird, sondern direkt zum nächsten Kunden gefahren wird, 0 sonst
dvar int+ x[T][J];         // Ladezeit an der Ladestation j zur Periode t in [min]
dvar int+ z[T0];           // Status (Reichweite) der Lithium-Ionen-Batterie am Ende der Periode t in [min]
dvar int+ theta[T];     // Leerzeit (Wartezeit ohne laden) an der Ladestation j zur Periode t

dvar int+ zeta[T][J];      // Hilfsvariable für x[t][j]

dexpr float Ladekosten = sum(j in J, t in T) (x[t][j]*c[j])*y[t][j];
dexpr float Eroeffnungskosten = sum(j in J, t in T) y[t][j]*o[j];
dexpr float Wartekosten = sum(j in J, t in T)theta[t]*g[j];
minimize Ladekosten + Eroeffnungskosten + Wartekosten;

constraint ctBatterieKapazitaet1[T];
constraint ctBatterieKapazitaet2[T];
constraint ctKundenabholung[T];
constraint ctMinuten[T][J];
//constraint ctTheta[T];

subject to {

//ZETA Linearisierung
forall (t in T)
L*sum(j in J)y[t][j] <= sum(j in J)zeta[t][j] ;

forall (t in T)
sum(j in J)zeta[t][j] <= U*sum(j in J)y[t][j];

forall (t in T)
sum(j in J)x[t][j] - U*(1-sum(j in J)y[t][j]) <= sum(j in J)zeta[t][j];

forall (t in T)
sum(j in J)zeta[t][j]<= sum(j in J)x[t][j] - L*(1-sum(j in J)y[t][j]);

//Programm

z[0] == 200;

z[t] == z[t-1] +  sum(j in J)(zeta[t][j] - (d[t][j])*y[t][j]) - r[t]*q[t] - f[t];

z[t]>= f[t+1]+sum(j in J)d1[t+1][j];

forall (t in T) ctBatterieKapazitaet1[t]:
z[t] <= K;

forall (t in T) ctBatterieKapazitaet2[t]:
z[t] >= W;

forall (t in T, j in J) ctMinuten[t][j]:
(x[t][j]) == sum(k in (f[t]+d1[t][j]+p1[t])..(p[t]+p1[t]-d2[t][j])) b[j][k] * y[t][j];

forall (t in T) ctKundenabholung[t]:
p[t] == f[t] + sum(j in J) (zeta[t][j] + d[t][j]*y[t][j]) + theta[t] + r[t]*q[t];

sum(j in J)y[t][j] + q[t] == 1;

```

• AlexFleischer
3277 Posts

#### Re: except some value

‏2017-03-28T13:34:16Z

I dont know its not working well. I changed the Data and all the necessary declaration.

Hi,

can you attach .mod and .dat ?

regards

• VYSN_Kai_Kühnel
17 Posts

#### Re: except some value

‏2017-03-28T13:56:53Z

Hi,

can you attach .mod and .dat ?

regards

Of course. Its attached.

#### Attachments

• AlexFleischer
3277 Posts

#### Re: except some value

‏2017-03-28T16:21:29Z

Of course. Its attached.

hI,

change

forall (t in T:t in T) ctLadenMinimum[t]:
z[t]>= f[t+1]+sum(j in J)d1[t+1][j];

into

forall (t in T:(t+1) in T) ctLadenMinimum[t]:
z[t]>= f[t+1]+sum(j in J)d1[t+1][j];

will help

regards

• VYSN_Kai_Kühnel
17 Posts

#### Re: except some value

‏2017-03-29T11:27:05Z

hI,

change

forall (t in T:t in T) ctLadenMinimum[t]:
z[t]>= f[t+1]+sum(j in J)d1[t+1][j];

into

forall (t in T:(t+1) in T) ctLadenMinimum[t]:
z[t]>= f[t+1]+sum(j in J)d1[t+1][j];

will help

regards

Thank you very much !!

Could you expain me how this can work ? Because I am interested why I do not need any new declaration in order to expand the periods?

Regards
Kai

• AlexFleischer
3277 Posts

#### Re: except some value

‏2017-03-29T11:36:50Z

Thank you very much !!

Could you expain me how this can work ? Because I am interested why I do not need any new declaration in order to expand the periods?

Regards
Kai

Hi

if you use the t+1 index you simply need to make sure that t+1 is in T. And slicing can do that.

Regards

PS:

Updated on 2017-03-29T11:37:33Z at 2017-03-29T11:37:33Z by AlexFleischer