Question: Problem with indexed coefficients with LPSolve (?)

Hi, I have a question about LPSolve. I definately have a linear polynomial as objective function, but LPSolve seems to think otherwise. My best guess is that it has to do with that my variables are indexed like that? Here is the code, I attached it as well.


restart;

with(Optimization); with(LinearAlgebra):

[ImportMPS, Interactive, LPSolve, LSSolve, Maximize, Minimize, NLPSolve, QPSolve]

(1)

#fix n, k:

n:=5; k:=2;

5

 

2

(2)

 

A[0]:= 1: A[1]:=0:

eqn:=  add(A[r],r=0..n)=2^(n-k);
eqs:= {}:

1+A[2]+A[3]+A[4]+A[5] = 8

(3)

for j from 0 to n do
 r:= 'r': s:='s':
 P[j]:= x -> add((-1)^s*3^(j-s)*binomial(x,s)*binomial(n-x,j-s),s=0..j):
 B[j]:=1/(2^(n-k))*add(A[r]*P[j](r),r=0..n);
od:
 

for j from 1 to n do
 eqs := eqs union { A[j] <= B[j] };
 eqs := eqs union {1/(2^(n-k-1))*(add(P[j](2*r)*A[2*r],r=0..floor(n/2))) >= B[j]};
od:

eqs;

{0 <= 15/8+(7/8)*A[2]+(3/8)*A[3]-(1/8)*A[4]-(5/8)*A[5], A[2] <= 45/4+(5/4)*A[2]-(3/4)*A[3]-(3/4)*A[4]+(5/4)*A[5], A[3] <= 135/4-(9/4)*A[2]-(5/4)*A[3]+(7/4)*A[4]-(5/4)*A[5], A[4] <= 405/8-(27/8)*A[2]+(21/8)*A[3]-(11/8)*A[4]+(5/8)*A[5], A[5] <= 243/8+(27/8)*A[2]-(9/8)*A[3]+(3/8)*A[4]-(1/8)*A[5], -(27/8)*A[2]+(21/8)*A[3]-(11/8)*A[4]+(5/8)*A[5] <= 405/8-(27/4)*A[2]-(11/4)*A[4], -(9/4)*A[2]-(5/4)*A[3]+(7/4)*A[4]-(5/4)*A[5] <= 135/4-(9/2)*A[2]+(7/2)*A[4], (5/4)*A[2]-(3/4)*A[3]-(3/4)*A[4]+(5/4)*A[5] <= 45/4+(5/2)*A[2]-(3/2)*A[4], (7/8)*A[2]+(3/8)*A[3]-(1/8)*A[4]-(5/8)*A[5] <= 15/8+(7/4)*A[2]-(1/4)*A[4], (27/8)*A[2]-(9/8)*A[3]+(3/8)*A[4]-(1/8)*A[5] <= 243/8+(27/4)*A[2]+(3/4)*A[4]}

(4)

j:= 'j': pos1:= { add(A[2*j],j=0..floor(n/2)) = 2^(n-k)}; j:= 'j': pos2:= { add(A[2*j],j=0..floor(n/2)) = 2^(n-k-1)};

{1+A[2]+A[4] = 8}

 

{1+A[2]+A[4] = 4}

(5)

j:='j':

debug(LPSolve);

Optimization:-LPSolve

(6)

for d from 1 to n do
j:='j': dist:= {add(A[j] - B[j], j=0..d) = 0};
LPSolve(eqn,(eqs union pos1 union dist),asadde={nonegative,integer});
od;

j

 

{-1-A[2]-(1/2)*A[3]+(1/2)*A[5] = 0}

 

{--> enter Optimization:-LPSolve, args = 1+A[2]+A[3]+A[4]+A[5] = 8, {1+A[2]+A[4] = 8, -1-A[2]-(1/2)*A[3]+(1/2)*A[5] = 0, 0 <= 15/8+(7/8)*A[2]+(3/8)*A[3]-(1/8)*A[4]-(5/8)*A[5], A[2] <= 45/4+(5/4)*A[2]-(3/4)*A[3]-(3/4)*A[4]+(5/4)*A[5], A[3] <= 135/4-(9/4)*A[2]-(5/4)*A[3]+(7/4)*A[4]-(5/4)*A[5], A[4] <= 405/8-(27/8)*A[2]+(21/8)*A[3]-(11/8)*A[4]+(5/8)*A[5], A[5] <= 243/8+(27/8)*A[2]-(9/8)*A[3]+(3/8)*A[4]-(1/8)*A[5], -(27/8)*A[2]+(21/8)*A[3]-(11/8)*A[4]+(5/8)*A[5] <= 405/8-(27/4)*A[2]-(11/4)*A[4], -(9/4)*A[2]-(5/4)*A[3]+(7/4)*A[4]-(5/4)*A[5] <= 135/4-(9/2)*A[2]+(7/2)*A[4], (5/4)*A[2]-(3/4)*A[3]-(3/4)*A[4]+(5/4)*A[5] <= 45/4+(5/2)*A[2]-(3/2)*A[4], (7/8)*A[2]+(3/8)*A[3]-(1/8)*A[4]-(5/8)*A[5] <= 15/8+(7/4)*A[2]-(1/4)*A[4], (27/8)*A[2]-(9/8)*A[3]+(3/8)*A[4]-(1/8)*A[5] <= 243/8+(27/4)*A[2]+(3/4)*A[4]}, asadde = {integer, nonegative}

 

true

 

15

 

0.111022302462516e-15

 

<-- ERROR in Optimization:-LPSolve (now at top level) = objective function must be specified as a linear polynomial or Vector}

Error, (in Optimization:-LPSolve) objective function must be specified as a linear polynomial or Vector

 

 

 


Download LP.mw

Please Wait...