[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-glpk] power of: calculate 2^x from variable x
From: |
malekro |
Subject: |
[Help-glpk] power of: calculate 2^x from variable x |
Date: |
Tue, 7 Jun 2011 19:09:26 -0700 (PDT) |
hello,
i am trying to calculate 2^x from a variable x. i already spent several
hours and with the help of archived posts i thought i have the solution.
unfortunately i cannot figure out why the code below returns an empty result
or malforms the x variable, i think the idea is correct.
set R := {0..3};
set C := {0..2};
# the given numbers that need to be powered by 2
var x{R}, integer;
# temporary table, each row will later be used for multiplication with 2^c
var t{R,C}, binary;
# the desired solution 2^x
var s{R}, integer;
# set the x-th cell in temporary row to 1, rest 0
s.t. c1{r in R}: sum{c in C} t[r,c] = 1; # exactly one 1 in row
s.t. c3{r in R, c in C}: c * t[r,c] = x[r]; # set the x[r]-th cell to 1
s.t. c2{r in R}: sum{c in C} c * t[r,c] = x[r]; # verification so t[r,0] !=
1 if x[r] > 0
# multiply the c-th cell of the temporary row with 2^c
s.t. c4{r in R}: s[r] = sum{c in C} (2 ** c) * t[r,c];
i would be grateful for any help.
thanks,
manuel
--
View this message in context:
http://old.nabble.com/power-of%3A-calculate-2%5Ex-from-variable-x-tp31797207p31797207.html
Sent from the Gnu - GLPK - Help mailing list archive at Nabble.com.
- [Help-glpk] power of: calculate 2^x from variable x,
malekro <=