Re: [Help-glpk] [Fwd: I: Modelling binary variable]

2013-10-10 Thread Nigel Galloway
Sorry wrong question, that tells me if the number set is odd or even.

-- 
  Nigel Galloway
  nigel_gallo...@operamail.com

On Thu, Oct 10, 2013, at 04:06 AM, Nigel Galloway wrote:
> Michael,
> 
> Does this not imply that we could just say sum = 2a + z where a is an
> integer >=0 and z is binary?
> 
> -- 
>   Nigel Galloway
>   nigel_gallo...@operamail.com
> 
> On Wed, Oct 9, 2013, at 06:00 AM, Meketon, Marc wrote:
> > Michael.  This is also very clever.
> > 
> > Another explanation of your code is the following:
> > 
> > Variable  a  is a non-negative integer (and always <= N2hi),  b  is
> > binary, z  is binary.  There are 4 constraints:
> > (1) sum=2a+b
> > (2) z>=b-a
> > (3) z<=b
> > (4) z<=(1-N2hi/N2lo)b - a/N2lo + N2hi/N2lo
> > 
> > When sum=1 we must have a=0, b=1.  Constraints (2) becomes z >= 1, (3)
> > becomes z <= 1, and (4) becomes z <=1.  Hence z = 1.
> > 
> > For any sum that is even,  a = sum/2 and  b=0.  Constraint (2) is then
> > non-binding since b-a <=0 and we know z >=0.  Constraint (3) is z <=0. 
> > Constraint (4) (since b=0) is z <= (N2hi - a)/N2lo.  Since  0 <= a <=
> > N2hi, this is a non-binding since constraint (3) is tighter.  Hence z=0.
> > 
> > For any sum that is odd, with sum >= 3, we know that 1 <= a <= N2lo and b
> > = 1.  Constraint (2) is non-binding because b-a <= 0.  Constraint (3)
> > with z <= 1 is non-binding.  Constraint (4) becomes z <= 1-a/N2lo.  Since
> > 1 <= a <= N2lo, we know 0 <= 1-a/N2lo < 1, implying z < 1 (strict
> > inequality), and then the binary constraint forces z=0.
> > 
> > 
> > -----Original Message-
> > From: Michael Hennebry [mailto:henne...@web.cs.ndsu.nodak.edu]
> > Sent: Tuesday, October 08, 2013 1:43 PM
> > To: Meketon, Marc
> > Cc: Nigel Galloway; Andrew Makhorin; help-glpk@gnu.org;
> > pietro.scio...@archinet.it
> > Subject: Re: [Help-glpk] [Fwd: I: Modelling binary variable]
> > 
> > On Tue, 8 Oct 2013, Meketon, Marc wrote:
> > 
> > > Are you sure that Z = Q[2]-Q[1]?  For the case where x[1]=1, x[2]=0, 
> > > x[3]=0, we have Q[1]=0, Q[2]=0, Q[3]=1, and then Q[3]-Q[2] = 1 which is 
> > > the correct answer.
> > 
> > Z = Q[1]-Q[2]
> > he has Q sorted in non-ascending order.
> > 00 no ones  0-0=0
> > 10 one one  1-0=1
> > 11 two or more ones 1-1=0
> > exactly what you want
> > The size of N does not matter.
> > 
> > Meketon's code has the advantage of ease of coding and understanding, but
> > it doubles the dimensionality.
> > 
> > Assume one has an integer expression sum:
> > 0<=sum<=N
> > One wants z==1 iff sum==1 else 0
> > Define N2lo=floor(N/2), N2hi=ceil(N/2)
> > Note N=N2lo+N2hi, H2hi-N2lo in {0, 1}
> > Add two (not N) more integer variables:
> > 0<=a<=N2hi
> > b binary
> > 
> > require
> > sum=2a+b
> > z>=b-a
> > z<=b
> > z<=(1-N2hi/N2lo)b - a/N2lo + N2hi/N2lo
> > 
> > The last constraint on z should be multiplied by N2lo to ensure
> > integrality of the coefficients.
> > 
> > Done.
> > 
> > The first two constraints on z are fairly obvious.
> > The last needs more explanation.
> > 
> > The diagram below is for N==7.
> > 
> > 3  0 -
> > 2  0 0
> >   a 1  0 0
> > 0  0 1
> > 
> >0 1
> >b
> > 
> > The rectangle gives the values of z for all valid combinations of a and
> > b.
> > The given constraints on z are all facets of the polyhedron.
> > The first is for facet (0, 0, 0)(0, 1, 1)(1, 0, 0).
> > The second for facet (0, 0, 0)(0, 1, 1)(N2hi, 0, 0).
> > The third for facet (N2lo, 1, 0)(0, 1, 1)(N2hi, 0, 0).
> > Substitution will verify.
> > 
> > 
> > Note that exhaustive testing is possible:
> > The number of combinations that need testing is at most 2*(N+1)**2 .
> > 
> > --
> > Michael   henne...@web.cs.ndsu.nodak.edu
> > "On Monday, I'm gonna have to tell my kindergarten class, whom I teach
> > not to run with scissors, that my fiance ran me through with a
> > broadsword."  --  Lily
> > 
> > This e-mail and any attachments may be confidential or legally
> > privileged. If you received this message in error or are not the intended
> > recipient, you should destroy the e-mail message and any attachments or
> > copies, and you are prohibited from retaining, distributing, disclosing
> > or using any information contained herein.  Please inform us of the
> > erroneous delivery by return e-mail. Thank you for your cooperation.
> 
> -- 
> http://www.fastmail.fm - Send your email first class
> 
> 
> ___
> Help-glpk mailing list
> Help-glpk@gnu.org
> https://lists.gnu.org/mailman/listinfo/help-glpk

-- 
http://www.fastmail.fm - IMAP accessible web-mail


___
Help-glpk mailing list
Help-glpk@gnu.org
https://lists.gnu.org/mailman/listinfo/help-glpk


Re: [Help-glpk] [Fwd: I: Modelling binary variable]

2013-10-10 Thread Nigel Galloway
Michael,

Does this not imply that we could just say sum = 2a + z where a is an
integer >=0 and z is binary?

-- 
  Nigel Galloway
  nigel_gallo...@operamail.com

On Wed, Oct 9, 2013, at 06:00 AM, Meketon, Marc wrote:
> Michael.  This is also very clever.
> 
> Another explanation of your code is the following:
> 
> Variable  a  is a non-negative integer (and always <= N2hi),  b  is
> binary, z  is binary.  There are 4 constraints:
> (1) sum=2a+b
> (2) z>=b-a
> (3) z<=b
> (4) z<=(1-N2hi/N2lo)b - a/N2lo + N2hi/N2lo
> 
> When sum=1 we must have a=0, b=1.  Constraints (2) becomes z >= 1, (3)
> becomes z <= 1, and (4) becomes z <=1.  Hence z = 1.
> 
> For any sum that is even,  a = sum/2 and  b=0.  Constraint (2) is then
> non-binding since b-a <=0 and we know z >=0.  Constraint (3) is z <=0. 
> Constraint (4) (since b=0) is z <= (N2hi - a)/N2lo.  Since  0 <= a <=
> N2hi, this is a non-binding since constraint (3) is tighter.  Hence z=0.
> 
> For any sum that is odd, with sum >= 3, we know that 1 <= a <= N2lo and b
> = 1.  Constraint (2) is non-binding because b-a <= 0.  Constraint (3)
> with z <= 1 is non-binding.  Constraint (4) becomes z <= 1-a/N2lo.  Since
> 1 <= a <= N2lo, we know 0 <= 1-a/N2lo < 1, implying z < 1 (strict
> inequality), and then the binary constraint forces z=0.
> 
> 
> -Original Message-
> From: Michael Hennebry [mailto:henne...@web.cs.ndsu.nodak.edu]
> Sent: Tuesday, October 08, 2013 1:43 PM
> To: Meketon, Marc
> Cc: Nigel Galloway; Andrew Makhorin; help-glpk@gnu.org;
> pietro.scio...@archinet.it
> Subject: Re: [Help-glpk] [Fwd: I: Modelling binary variable]
> 
> On Tue, 8 Oct 2013, Meketon, Marc wrote:
> 
> > Are you sure that Z = Q[2]-Q[1]?  For the case where x[1]=1, x[2]=0, 
> > x[3]=0, we have Q[1]=0, Q[2]=0, Q[3]=1, and then Q[3]-Q[2] = 1 which is the 
> > correct answer.
> 
> Z = Q[1]-Q[2]
> he has Q sorted in non-ascending order.
> 00 no ones  0-0=0
> 10 one one  1-0=1
> 11 two or more ones 1-1=0
> exactly what you want
> The size of N does not matter.
> 
> Meketon's code has the advantage of ease of coding and understanding, but
> it doubles the dimensionality.
> 
> Assume one has an integer expression sum:
> 0<=sum<=N
> One wants z==1 iff sum==1 else 0
> Define N2lo=floor(N/2), N2hi=ceil(N/2)
> Note N=N2lo+N2hi, H2hi-N2lo in {0, 1}
> Add two (not N) more integer variables:
> 0<=a<=N2hi
> b binary
> 
> require
> sum=2a+b
> z>=b-a
> z<=b
> z<=(1-N2hi/N2lo)b - a/N2lo + N2hi/N2lo
> 
> The last constraint on z should be multiplied by N2lo to ensure
> integrality of the coefficients.
> 
> Done.
> 
> The first two constraints on z are fairly obvious.
> The last needs more explanation.
> 
> The diagram below is for N==7.
> 
> 3  0 -
> 2  0 0
>   a 1  0 0
> 0  0 1
> 
>0 1
>b
> 
> The rectangle gives the values of z for all valid combinations of a and
> b.
> The given constraints on z are all facets of the polyhedron.
> The first is for facet (0, 0, 0)(0, 1, 1)(1, 0, 0).
> The second for facet (0, 0, 0)(0, 1, 1)(N2hi, 0, 0).
> The third for facet (N2lo, 1, 0)(0, 1, 1)(N2hi, 0, 0).
> Substitution will verify.
> 
> 
> Note that exhaustive testing is possible:
> The number of combinations that need testing is at most 2*(N+1)**2 .
> 
> --
> Michael   henne...@web.cs.ndsu.nodak.edu
> "On Monday, I'm gonna have to tell my kindergarten class, whom I teach
> not to run with scissors, that my fiance ran me through with a
> broadsword."  --  Lily
> 
> This e-mail and any attachments may be confidential or legally
> privileged. If you received this message in error or are not the intended
> recipient, you should destroy the e-mail message and any attachments or
> copies, and you are prohibited from retaining, distributing, disclosing
> or using any information contained herein.  Please inform us of the
> erroneous delivery by return e-mail. Thank you for your cooperation.

-- 
http://www.fastmail.fm - Send your email first class


___
Help-glpk mailing list
Help-glpk@gnu.org
https://lists.gnu.org/mailman/listinfo/help-glpk


Re: [Help-glpk] [Fwd: I: Modelling binary variable]

2013-10-09 Thread Meketon, Marc
Michael.  This is also very clever.

Another explanation of your code is the following:

Variable  a  is a non-negative integer (and always <= N2hi),  b  is binary, z  
is binary.  There are 4 constraints:
(1) sum=2a+b
(2) z>=b-a
(3) z<=b
(4) z<=(1-N2hi/N2lo)b - a/N2lo + N2hi/N2lo

When sum=1 we must have a=0, b=1.  Constraints (2) becomes z >= 1, (3) becomes 
z <= 1, and (4) becomes z <=1.  Hence z = 1.

For any sum that is even,  a = sum/2 and  b=0.  Constraint (2) is then 
non-binding since b-a <=0 and we know z >=0.  Constraint (3) is z <=0.  
Constraint (4) (since b=0) is z <= (N2hi - a)/N2lo.  Since  0 <= a <= N2hi, 
this is a non-binding since constraint (3) is tighter.  Hence z=0.

For any sum that is odd, with sum >= 3, we know that 1 <= a <= N2lo and b = 1.  
Constraint (2) is non-binding because b-a <= 0.  Constraint (3) with z <= 1 is 
non-binding.  Constraint (4) becomes z <= 1-a/N2lo.  Since 1 <= a <= N2lo, we 
know 0 <= 1-a/N2lo < 1, implying z < 1 (strict inequality), and then the binary 
constraint forces z=0.


-Original Message-
From: Michael Hennebry [mailto:henne...@web.cs.ndsu.nodak.edu]
Sent: Tuesday, October 08, 2013 1:43 PM
To: Meketon, Marc
Cc: Nigel Galloway; Andrew Makhorin; help-glpk@gnu.org; 
pietro.scio...@archinet.it
Subject: Re: [Help-glpk] [Fwd: I: Modelling binary variable]

On Tue, 8 Oct 2013, Meketon, Marc wrote:

> Are you sure that Z = Q[2]-Q[1]?  For the case where x[1]=1, x[2]=0, x[3]=0, 
> we have Q[1]=0, Q[2]=0, Q[3]=1, and then Q[3]-Q[2] = 1 which is the correct 
> answer.

Z = Q[1]-Q[2]
he has Q sorted in non-ascending order.
00 no ones  0-0=0
10 one one  1-0=1
11 two or more ones 1-1=0
exactly what you want
The size of N does not matter.

Meketon's code has the advantage of ease of coding and understanding, but it 
doubles the dimensionality.

Assume one has an integer expression sum:
0<=sum<=N
One wants z==1 iff sum==1 else 0
Define N2lo=floor(N/2), N2hi=ceil(N/2)
Note N=N2lo+N2hi, H2hi-N2lo in {0, 1}
Add two (not N) more integer variables:
0<=a<=N2hi
b binary

require
sum=2a+b
z>=b-a
z<=b
z<=(1-N2hi/N2lo)b - a/N2lo + N2hi/N2lo

The last constraint on z should be multiplied by N2lo to ensure integrality of 
the coefficients.

Done.

The first two constraints on z are fairly obvious.
The last needs more explanation.

The diagram below is for N==7.

3  0 -
2  0 0
  a 1  0 0
0  0 1

   0 1
   b

The rectangle gives the values of z for all valid combinations of a and b.
The given constraints on z are all facets of the polyhedron.
The first is for facet (0, 0, 0)(0, 1, 1)(1, 0, 0).
The second for facet (0, 0, 0)(0, 1, 1)(N2hi, 0, 0).
The third for facet (N2lo, 1, 0)(0, 1, 1)(N2hi, 0, 0).
Substitution will verify.


Note that exhaustive testing is possible:
The number of combinations that need testing is at most 2*(N+1)**2 .

--
Michael   henne...@web.cs.ndsu.nodak.edu
"On Monday, I'm gonna have to tell my kindergarten class, whom I teach not to 
run with scissors, that my fiance ran me through with a broadsword."  --  Lily

This e-mail and any attachments may be confidential or legally privileged. If 
you received this message in error or are not the intended recipient, you 
should destroy the e-mail message and any attachments or copies, and you are 
prohibited from retaining, distributing, disclosing or using any information 
contained herein.  Please inform us of the erroneous delivery by return e-mail. 
Thank you for your cooperation.

___
Help-glpk mailing list
Help-glpk@gnu.org
https://lists.gnu.org/mailman/listinfo/help-glpk


Re: [Help-glpk] [Fwd: I: Modelling binary variable]

2013-10-08 Thread Meketon, Marc
It was Nigel Galloway's code, not my code.

-Original Message-
From: Michael Hennebry [mailto:henne...@web.cs.ndsu.nodak.edu]
Sent: Tuesday, October 08, 2013 1:43 PM
To: Meketon, Marc
Cc: Nigel Galloway; Andrew Makhorin; help-glpk@gnu.org; 
pietro.scio...@archinet.it
Subject: Re: [Help-glpk] [Fwd: I: Modelling binary variable]

On Tue, 8 Oct 2013, Meketon, Marc wrote:

> Are you sure that Z = Q[2]-Q[1]?  For the case where x[1]=1, x[2]=0, x[3]=0, 
> we have Q[1]=0, Q[2]=0, Q[3]=1, and then Q[3]-Q[2] = 1 which is the correct 
> answer.

Z = Q[1]-Q[2]
he has Q sorted in non-ascending order.
00 no ones  0-0=0
10 one one  1-0=1
11 two or more ones 1-1=0
exactly what you want
The size of N does not matter.

Meketon's code has the advantage of ease of coding and understanding, but it 
doubles the dimensionality.

Assume one has an integer expression sum:
0<=sum<=N
One wants z==1 iff sum==1 else 0
Define N2lo=floor(N/2), N2hi=ceil(N/2)
Note N=N2lo+N2hi, H2hi-N2lo in {0, 1}
Add two (not N) more integer variables:
0<=a<=N2hi
b binary

require
sum=2a+b
z>=b-a
z<=b
z<=(1-N2hi/N2lo)b - a/N2lo + N2hi/N2lo

The last constraint on z should be multiplied by N2lo to ensure integrality of 
the coefficients.

Done.

The first two constraints on z are fairly obvious.
The last needs more explanation.

The diagram below is for N==7.

3  0 -
2  0 0
  a 1  0 0
0  0 1

   0 1
   b

The rectangle gives the values of z for all valid combinations of a and b.
The given constraints on z are all facets of the polyhedron.
The first is for facet (0, 0, 0)(0, 1, 1)(1, 0, 0).
The second for facet (0, 0, 0)(0, 1, 1)(N2hi, 0, 0).
The third for facet (N2lo, 1, 0)(0, 1, 1)(N2hi, 0, 0).
Substitution will verify.


Note that exhaustive testing is possible:
The number of combinations that need testing is at most 2*(N+1)**2 .

--
Michael   henne...@web.cs.ndsu.nodak.edu
"On Monday, I'm gonna have to tell my kindergarten class, whom I teach not to 
run with scissors, that my fiance ran me through with a broadsword."  --  Lily

This e-mail and any attachments may be confidential or legally privileged. If 
you received this message in error or are not the intended recipient, you 
should destroy the e-mail message and any attachments or copies, and you are 
prohibited from retaining, distributing, disclosing or using any information 
contained herein.  Please inform us of the erroneous delivery by return e-mail. 
Thank you for your cooperation.

___
Help-glpk mailing list
Help-glpk@gnu.org
https://lists.gnu.org/mailman/listinfo/help-glpk


Re: [Help-glpk] [Fwd: I: Modelling binary variable]

2013-10-08 Thread Michael Hennebry

On Tue, 8 Oct 2013, Meketon, Marc wrote:


Are you sure that Z = Q[2]-Q[1]?  For the case where x[1]=1, x[2]=0, x[3]=0, we 
have Q[1]=0, Q[2]=0, Q[3]=1, and then Q[3]-Q[2] = 1 which is the correct answer.


Z = Q[1]-Q[2]
he has Q sorted in non-ascending order.
00 no ones  0-0=0
10 one one  1-0=1
11 two or more ones 1-1=0
exactly what you want
The size of N does not matter.

Meketon's code has the advantage of ease of coding and understanding,
but it doubles the dimensionality.

Assume one has an integer expression sum:
0<=sum<=N
One wants z==1 iff sum==1 else 0
Define N2lo=floor(N/2), N2hi=ceil(N/2)
Note N=N2lo+N2hi, H2hi-N2lo in {0, 1}
Add two (not N) more integer variables:
0<=a<=N2hi
b binary

require
sum=2a+b
z>=b-a
z<=b
z<=(1-N2hi/N2lo)b - a/N2lo + N2hi/N2lo

The last constraint on z should be multiplied by
N2lo to ensure integrality of the coefficients.

Done.

The first two constraints on z are fairly obvious.
The last needs more explanation.

The diagram below is for N==7.

   3  0 -
   2  0 0
 a 1  0 0
   0  0 1

  0 1
  b

The rectangle gives the values of z for all valid combinations of a and b.
The given constraints on z are all facets of the polyhedron.
The first is for facet (0, 0, 0)(0, 1, 1)(1, 0, 0).
The second for facet (0, 0, 0)(0, 1, 1)(N2hi, 0, 0).
The third for facet (N2lo, 1, 0)(0, 1, 1)(N2hi, 0, 0).
Substitution will verify.


Note that exhaustive testing is possible:
The number of combinations that need testing is at most 2*(N+1)**2 .

--
Michael   henne...@web.cs.ndsu.nodak.edu
"On Monday, I'm gonna have to tell my kindergarten class,
whom I teach not to run with scissors,
that my fiance ran me through with a broadsword."  --  Lily

___
Help-glpk mailing list
Help-glpk@gnu.org
https://lists.gnu.org/mailman/listinfo/help-glpk


Re: [Help-glpk] [Fwd: I: Modelling binary variable]

2013-10-08 Thread Meketon, Marc
Hi Nigel.  This is very clever.

Are you sure that Z = Q[2]-Q[1]?  For the case where x[1]=1, x[2]=0, x[3]=0, we 
have Q[1]=0, Q[2]=0, Q[3]=1, and then Q[3]-Q[2] = 1 which is the correct answer.

For n larger than three, Z would be Q[n] - Q[n-1]



-Original Message-
From: help-glpk-bounces+marc.meketon=oliverwyman@gnu.org 
[mailto:help-glpk-bounces+marc.meketon=oliverwyman@gnu.org] On Behalf Of 
Nigel Galloway
Sent: Tuesday, October 08, 2013 8:16 AM
To: Andrew Makhorin; help-glpk@gnu.org; pietro.scio...@archinet.it
Subject: Re: [Help-glpk] [Fwd: I: Modelling binary variable]

Change N to create a larger array. I present test results for all combinations 
when N is 3. I leave it to readers to convince themselves that it works for all 
combinations for any given N.

/*
  Set Z to 1 if one and only one of an array of binary variables is 1.

  nigel_gallo...@operamail.com
  October 7th., 2013
*/

param N := 3;
var x{n in 1..N} , binary;
var Q{n in 1..N} , binary;

st1 : sum{n in 1..N} x[n] = sum{n in 1..N} Q[n];
st2 {n in 1..N-1} : 0 <= Q[n] - Q[n+1];

st90 : x[1] = 1;
st91 : x[2] = 1;
st92 : x[3] = 1;
solve;

printf "x[1] = %d, x[2] = %d, x[3] = %d, and Z = %d\n",x[1],x[2],x[3],Q[1] - 
Q[2];

end;

/*

Changing st90, st91 and st92 for the eight possible combinations
produces:

INTEGER OPTIMAL SOLUTION FOUND BY MIP PREPROCESSOR
Time used:   0.0 secs
Memory used: 0.1 Mb (104314 bytes)
x[1] = 1, x[2] = 1, x[3] = 1, and Z = 0
Model has been successfully processed

INTEGER OPTIMAL SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.1 Mb (119549 bytes)
x[1] = 1, x[2] = 1, x[3] = 0, and Z = 0
Model has been successfully processed

INTEGER OPTIMAL SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.1 Mb (119549 bytes)
x[1] = 1, x[2] = 0, x[3] = 1, and Z = 0
Model has been successfully processed

INTEGER OPTIMAL SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.1 Mb (119549 bytes)
x[1] = 0, x[2] = 1, x[3] = 1, and Z = 0
Model has been successfully processed

INTEGER OPTIMAL SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.1 Mb (119549 bytes)
x[1] = 0, x[2] = 1, x[3] = 0, and Z = 1
Model has been successfully processed

INTEGER OPTIMAL SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.1 Mb (119549 bytes)
x[1] = 1, x[2] = 0, x[3] = 0, and Z = 1
Model has been successfully processed

INTEGER OPTIMAL SOLUTION FOUND BY MIP PREPROCESSOR
Time used:   0.0 secs
Memory used: 0.1 Mb (104314 bytes)
x[1] = 0, x[2] = 0, x[3] = 0, and Z = 0
Model has been successfully processed
*/


--
  Nigel Galloway
  nigel_gallo...@operamail.com

On Wed, Oct 2, 2013, at 11:41 AM, Andrew Makhorin wrote:
>  Forwarded Message 
> From: Pietro Scionti 
> To: m...@gnu.org 
> Subject: I: Modelling binary variable
> Date: Wed, 2 Oct 2013 17:52:19 +0200
>
> Hi Andrew,
>
> I sent this message to the list but I’ve never seen it appear in the
> digest or the online archives. Is the address changed since the last
> time I used it?
>
> Thank you very much
>
> Pietro
>
>
>
> Da: Pietro Scionti
> Inviato: lunedì 23 settembre 2013 10:50
> A: 'help-glpk@gnu.org'
> Oggetto: Modelling binary variable
>
>
>
>
> Hi everyone,
>
> I need help to model this situation: I have a series of binary
> decision variables
>
> var x{o in O, t in T, g in G}
>
> and I want to introduce a new binary variable
>
> var z{o in O, t in T}
>
> which takes 1 if and only if
>
> sum{g in G} x[o,t,g] = 1
>
>
>
> I tried using a Big-M approach but it only covered one of the two
> implications.
>
> Any suggestions?
>
>
>
> Thanks,
>
> Pietro
>
>
>
>
> __
> __
>
> Archimede S.r.l.
> Sede Legale:
> Via Manzoni, 82
> Ponte S. Giovanni
>
> P.IVA: 01992020543
>
> Tel. 075 515 22 11
> Fax. 075 515 22 99
> www.archinet.it
>
> **
> **
> **
>  La presente comunicazione, con le informazioni in essa contenute
> e ogni documento o file allegato, e' rivolta unicamente alla/e
> persona/e cui e'
> indirizzata ed alle altre da questa autorizzata/e a riceverla. Se non
> siete i destinatari/autorizzati siete avvisati che qualsiasi azione,
> copia, comunicazione, divulgazione o simili basate sul contenuto di
> tali informazioni e' vietata e potrebbe essere contro la legge (art.
> 616 C.P., D.Lgs n. 196/2003 Codice in materia di protezione dei dati
> personali). Se avete ricevuto questa comunicazione per errore, vi
> preghiamo di darne immediata notizia al mittente e di distruggere il
> messaggio originale e ogni

Re: [Help-glpk] [Fwd: I: Modelling binary variable]

2013-10-08 Thread Nigel Galloway
Change N to create a larger array. I present test results for all
combinations when N is 3. I leave it to readers to convince themselves
that it works for all combinations for any given N.

/*
  Set Z to 1 if one and only one of an array of binary variables is 1.

  nigel_gallo...@operamail.com
  October 7th., 2013
*/

param N := 3;
var x{n in 1..N} , binary;
var Q{n in 1..N} , binary;

st1 : sum{n in 1..N} x[n] = sum{n in 1..N} Q[n];
st2 {n in 1..N-1} : 0 <= Q[n] - Q[n+1];

st90 : x[1] = 1;
st91 : x[2] = 1;
st92 : x[3] = 1;
solve;

printf "x[1] = %d, x[2] = %d, x[3] = %d, and Z =
%d\n",x[1],x[2],x[3],Q[1] - Q[2];

end;

/*

Changing st90, st91 and st92 for the eight possible combinations
produces:

INTEGER OPTIMAL SOLUTION FOUND BY MIP PREPROCESSOR
Time used:   0.0 secs
Memory used: 0.1 Mb (104314 bytes)
x[1] = 1, x[2] = 1, x[3] = 1, and Z = 0
Model has been successfully processed

INTEGER OPTIMAL SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.1 Mb (119549 bytes)
x[1] = 1, x[2] = 1, x[3] = 0, and Z = 0
Model has been successfully processed

INTEGER OPTIMAL SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.1 Mb (119549 bytes)
x[1] = 1, x[2] = 0, x[3] = 1, and Z = 0
Model has been successfully processed

INTEGER OPTIMAL SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.1 Mb (119549 bytes)
x[1] = 0, x[2] = 1, x[3] = 1, and Z = 0
Model has been successfully processed

INTEGER OPTIMAL SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.1 Mb (119549 bytes)
x[1] = 0, x[2] = 1, x[3] = 0, and Z = 1
Model has been successfully processed

INTEGER OPTIMAL SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.1 Mb (119549 bytes)
x[1] = 1, x[2] = 0, x[3] = 0, and Z = 1
Model has been successfully processed

INTEGER OPTIMAL SOLUTION FOUND BY MIP PREPROCESSOR
Time used:   0.0 secs
Memory used: 0.1 Mb (104314 bytes)
x[1] = 0, x[2] = 0, x[3] = 0, and Z = 0
Model has been successfully processed
*/


-- 
  Nigel Galloway
  nigel_gallo...@operamail.com

On Wed, Oct 2, 2013, at 11:41 AM, Andrew Makhorin wrote:
>  Forwarded Message 
> From: Pietro Scionti 
> To: m...@gnu.org 
> Subject: I: Modelling binary variable
> Date: Wed, 2 Oct 2013 17:52:19 +0200
> 
> Hi Andrew,
> 
> I sent this message to the list but I’ve never seen it appear in the
> digest or the online archives. Is the address changed since the last
> time I used it?
> 
> Thank you very much
> 
> Pietro
> 
>  
> 
> Da: Pietro Scionti 
> Inviato: lunedì 23 settembre 2013 10:50
> A: 'help-glpk@gnu.org'
> Oggetto: Modelling binary variable
> 
> 
>  
> 
> Hi everyone,
> 
> I need help to model this situation: I have a series of binary decision
> variables
> 
> var x{o in O, t in T, g in G}
> 
> and I want to introduce a new binary variable
> 
> var z{o in O, t in T}
> 
> which takes 1 if and only if
> 
> sum{g in G} x[o,t,g] = 1
> 
>  
> 
> I tried using a Big-M approach but it only covered one of the two
> implications.
> 
> Any suggestions?
> 
>  
> 
> Thanks,
> 
> Pietro
> 
> 
> 
> 
> 
> 
> Archimede S.r.l.
> Sede Legale:
> Via Manzoni, 82
> Ponte S. Giovanni
> 
> P.IVA: 01992020543
> 
> Tel. 075 515 22 11
> Fax. 075 515 22 99
> www.archinet.it
> 
> **
> La presente comunicazione, con le informazioni in essa contenute e ogni
> documento o file allegato, e' rivolta unicamente alla/e persona/e cui e'
> indirizzata ed alle altre da questa autorizzata/e a riceverla. Se non
> siete i destinatari/autorizzati siete avvisati che qualsiasi azione,
> copia, comunicazione, divulgazione o simili basate sul contenuto di tali
> informazioni e' vietata e potrebbe essere contro la legge (art. 616
> C.P., D.Lgs n. 196/2003 Codice in materia di protezione dei dati
> personali). Se avete ricevuto questa comunicazione per errore, vi
> preghiamo di darne immediata notizia al mittente e di distruggere il
> messaggio originale e ogni file allegato senza farne copia alcuna o
> riprodurne in alcun modo il contenuto.
> 
> This e-mail and its attachments are intended for the addressee(s) only
> and are confidential and/or may contain legally privileged information.
> If you have received this message by mistake or are not one of the
> addressees above, you may take no action based on it, and you may not
> copy or show it to anyone; please reply to this e-mail and point out the
> error which has occurred.
> **
> 
> 
> 
> ___
> Help-glpk mailing list
> Help-glpk@gnu.org
> https://lists.gnu.org/mailman/listinfo/help-glpk

-- 
http://www.fastmai

[Help-glpk] [Fwd: I: Modelling binary variable]

2013-10-02 Thread Andrew Makhorin
 Forwarded Message 
From: Pietro Scionti 
To: m...@gnu.org 
Subject: I: Modelling binary variable
Date: Wed, 2 Oct 2013 17:52:19 +0200

Hi Andrew,

I sent this message to the list but I’ve never seen it appear in the
digest or the online archives. Is the address changed since the last
time I used it?

Thank you very much

Pietro

 

Da: Pietro Scionti 
Inviato: lunedì 23 settembre 2013 10:50
A: 'help-glpk@gnu.org'
Oggetto: Modelling binary variable


 

Hi everyone,

I need help to model this situation: I have a series of binary decision
variables

var x{o in O, t in T, g in G}

and I want to introduce a new binary variable

var z{o in O, t in T}

which takes 1 if and only if

sum{g in G} x[o,t,g] = 1

 

I tried using a Big-M approach but it only covered one of the two
implications.

Any suggestions?

 

Thanks,

Pietro






Archimede S.r.l.
Sede Legale:
Via Manzoni, 82
Ponte S. Giovanni

P.IVA: 01992020543

Tel. 075 515 22 11
Fax. 075 515 22 99
www.archinet.it

**
La presente comunicazione, con le informazioni in essa contenute e ogni
documento o file allegato, e' rivolta unicamente alla/e persona/e cui e'
indirizzata ed alle altre da questa autorizzata/e a riceverla. Se non
siete i destinatari/autorizzati siete avvisati che qualsiasi azione,
copia, comunicazione, divulgazione o simili basate sul contenuto di tali
informazioni e' vietata e potrebbe essere contro la legge (art. 616
C.P., D.Lgs n. 196/2003 Codice in materia di protezione dei dati
personali). Se avete ricevuto questa comunicazione per errore, vi
preghiamo di darne immediata notizia al mittente e di distruggere il
messaggio originale e ogni file allegato senza farne copia alcuna o
riprodurne in alcun modo il contenuto.

This e-mail and its attachments are intended for the addressee(s) only
and are confidential and/or may contain legally privileged information.
If you have received this message by mistake or are not one of the
addressees above, you may take no action based on it, and you may not
copy or show it to anyone; please reply to this e-mail and point out the
error which has occurred.
**



___
Help-glpk mailing list
Help-glpk@gnu.org
https://lists.gnu.org/mailman/listinfo/help-glpk