Re: [Help-glpk] Modelling constaints

2015-03-30 Thread Michael Hennebry

On Thu, 26 Mar 2015, john tass wrote:


Let U, K in {-6, .. , 6} integers
Let A in {0, 1} binary
Let D in {0, 1} binary
What I want to do  is to model the condition:
D = 1, iff (U  0 OR K  0) AND A = 1
Otherwise, D should equal 0.
I can not figure out how to model this situation.
Can any one give me an answear or even a hint? It would be very welcome.


I'd suggest two binaries to flag U=1 and K=1 .
Call them Qu and Qk respectively.

u want Qu = 1 - U=1
U = 1 - (1-Qu)*M
making M big enough will ensure that U can be in -6..0 when Qu=0
-6 = 1 - (1-0)*M
M=7 will work
U - 7*Qu = -6

You want Qu = 0 - -U=0 .
The same kind of math gives
-U + 6*Qu = 0

Likewise for Qk:
U - 7*Qk = -6
-U +6*Qk =  0

Another way to get those constraints is to graph the valid values.
The extreme points for (Qu, U) are:
(0, -6) (0, 0) (1, 1) (1, 6)

Now you just need constraints on the binaries A, D, Qu and Qk.
Doing it crudely, you could use 8 constraints
to cut off each of 8 invalid combinations.
Actually, you only need 4 constraints.
To help you find them, a Karnaugh Map might help:
http://en.wikipedia.org/wiki/Karnaugh_map
You will be more interested in zeros than in ones.

--
Michael   henne...@web.cs.ndsu.nodak.edu
SCSI is NOT magic. There are *fundamental technical
reasons* why it is necessary to sacrifice a young
goat to your SCSI chain now and then.   --   John Woods

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


Re: [Help-glpk] Modelling constaints

2015-03-27 Thread kolos . agoston

Try this:



Let UU=U+6 and KK K+6. So U0 means UU=7 and K0 means KK=7

UU=6+6s1

KK=6+6s2

s1+s2+2A=2+2s3

s3=D



s4=D


s5+s6+2A=3s4


UU=7s5

KK=7s6



All the s variables are binary. I am not sure, but I think it works.



Best wishes:



Kolos





Todays Topics:

1. Modelling constaints (john tass)


--

Message: 1
Date: Thu, 26 Mar 2015 23:10:59 +0200
From: john tass johnyt...@gmail.com
To: help-glpk@gnu.org
Subject: [Help-glpk] Modelling constaints
Message-ID:
cafr_-8cbvbsh-ur-d7copwnxuu1yy94eww+47pox8fvkvqv...@mail.gmail.com
Content-Type: text/plain; charset=utf-8

Good evening to every one,
I have a problem in modelling the following situation:
Let U, K in {-6, .. , 6} integers
Let A in {0, 1} binary
Let D in {0, 1} binary
What I want to do is to model the condition:
D = 1, iff (U  0 OR K  0) AND A = 1
Otherwise, D should equal 0.
I can not figure out how to model this situation.
Can any one give me an answear or even a hint? It would be very welcome.
Thanks a lot

--
Ioannis X. Tassopoulos
-- next part --
An HTML attachment was scrubbed...
URL: http://lists.gnu.org/archive/html/help-glpk/attachments/20150326/c0a1cce1/attachment.html

--

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


End of Help-glpk Digest, Vol 148, Issue 10
**




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


Re: [Help-glpk] Modelling constaints

2015-03-27 Thread john tass
Very good idea! Thank you very much.
I would like to add though, that because I want to get D = 0 in case A = 0
or ((U = 0 AND K = 0), I have to add the two constraints : D = A , D =
E.
Am I correct?
Thanks again

2015-03-28 0:24 GMT+02:00 Norman Jessup njes...@tpg.com.au:

  Hello Ioannis.

 If I understand your problem correctly, you can achieve the result you
 need using the Big M method, though I think you may need to introduce
 some new integer variables

 Let E in {0, 1} binaryM*E = U
 M*E = K

 Where M is some large positive constant, though in this particular case
 it just needs to be greater than 6.  This will force E to be positive if
 either U or K is positive.

 D = A + E - 1

 This will require D to be positive if both A and E are positive.  Note
 that for this to work the objective must prefer to drive D to zero if
 possible, which typically turns out to be the case.  If not then you will
 need to add complementary constraints to drive D to zero if the conditions
 are not met.

 On 28/03/2015 3:00 am, help-glpk-requ...@gnu.org wrote:

 Good evening to every one,
 I have a problem in modelling the following situation:
 Let U, K in {-6, .. , 6} integers
 Let A in {0, 1} binary
 Let D in {0, 1} binary
 What I want to do  is to model the condition:
 D = 1, iff (U  0 OR K  0) AND A = 1
 Otherwise, D should equal 0.
 I can not figure out how to model this situation.
 Can any one give me an answear or even a hint? It would be very welcome.
 Thanks a lot

  --
 Norman Jessup



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




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


Re: [Help-glpk] Modelling constaints

2015-03-27 Thread Norman Jessup

Hello Ioannis.

You may be correct. As I indicated earlier, very often the objective 
function will drive D down to zero unless the constraints force it 
otherwise.  In the models I build that invariably seems to be the case.  
If that doesn't apply to you or you are not 100% sure, you could add 
further constraints.  For example, you could have:


D = A
D = U+K

I think this would do what you need

regards

Norman Jessup

On 28/03/2015 9:56 am, john tass wrote:

Very good idea! Thank you very much.
I would like to add though, that because I want to get D = 0 in case A 
= 0 or ((U = 0 AND K = 0), I have to add the two constraints : D = 
A , D = E.

Am I correct?
Thanks again

2015-03-28 0:24 GMT+02:00 Norman Jessup njes...@tpg.com.au 
mailto:njes...@tpg.com.au:


Hello Ioannis.

If I understand your problem correctly, you can achieve the result
you need using the Big M method, though I think you may need to
introduce some new integer variables

Let E in {0, 1} binary
M*E = U
M*E = K

Where M is some large positive constant, though in this
particular case it just needs to be greater than 6.  This will
force E to be positive if either U or K is positive.

D = A + E - 1

This will require D to be positive if both A and E are positive. 
Note that for this to work the objective must prefer to drive D to

zero if possible, which typically turns out to be the case.  If
not then you will need to add complementary constraints to drive D
to zero if the conditions are not met.

On 28/03/2015 3:00 am, help-glpk-requ...@gnu.org
mailto:help-glpk-requ...@gnu.org wrote:

Good evening to every one,
I have a problem in modelling the following situation:
Let U, K in {-6, .. , 6} integers
Let A in {0, 1} binary
Let D in {0, 1} binary
What I want to do  is to model the condition:
D = 1, iff (U  0 OR K  0) AND A = 1
Otherwise, D should equal 0.
I can not figure out how to model this situation.
Can any one give me an answear or even a hint? It would be very welcome.
Thanks a lot




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