solve linear programming

187 views
Skip to first unread message

Yi

unread,
Jul 12, 2017, 10:57:24 AM7/12/17
to numericjs
For the linear programming function solveLP,  how can we set a upper bound and lower bound for the solution?  Like what the linprog function does in matlab, linprog(c, A,b,Aeq,beq, lb,ub), where lb and ub are the lower bound and upper bound.

Sébastien Loisel

unread,
Jul 12, 2017, 11:10:57 AM7/12/17
to nume...@googlegroups.com
Hi,

You have to use the matrix A and vector b for everything. This is an example for minimizing x-y in (1<x<2 and 1<y<2):


On 12 July 2017 at 15:57, Yi <guo...@seas.upenn.edu> wrote:
For the linear programming function solveLP,  how can we set a upper bound and lower bound for the solution?  Like what the linprog function does in matlab, linprog(c, A,b,Aeq,beq, lb,ub), where lb and ub are the lower bound and upper bound.

--
You received this message because you are subscribed to the Google Groups "numericjs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numericjs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Sébastien Loisel
Assistant Professor
Department of Mathematics, Heriot-Watt University
Riccarton, EH14 4AS, United Kingdom
web: http://www.ma.hw.ac.uk/~loisel/
email: S.Loisel at hw.ac.uk
phone: +44 131 451 3234
fax: +44 131 451 3249

Message has been deleted

Yi

unread,
Jul 27, 2017, 5:40:55 PM7/27/17
to numericjs
Hi sloisel, 
Appreciate for answering my question. But I met another bug when using the solveLP(m_C,m_A,m_b,m_Aeq,m_beq). When there are all-zero rows in m_Aeq, I always get a solution including NaN.  Even though I delete those all-zero rows, sometimes I still get NaN in the solution.

Here is an easy example. I want to minimize the sum of all the elements in the solution with the constraints that Ax=0 and all the elements in x must be no less than 1.  Like this:
    var m_Aeq=[
                [-1,0,1,0,0,0,0,0,0,0,0,0],
                [0,1,0,-1,0,0,0,0,0,0,0,0],
                [0,0,0,-1,0,1,0,0,0,0,0,0],
                [0,0,0,0,1,0,-1,0,0,0,0,0],
                [0,0,1,0,0,0,0,0,-1,0,0,0],
                [0,0,0,0,0,0,1,-1,0,0,0,0],
                [-1,0,0,0,0,0,0,0,0,0,1,0],
                [0,0,0,0,-1,0,0,0,0,1,0,0],
                [0,0,0,0,0,0,0,0,1,0,-1,0],
                [0,0,0,0,0,-1,0,0,0,0,0,1]];
var m_A=[];
    for(var i=0;i<12;i++)
    {
        m_A[i]=new Array(12);
        m_A[i].fill(0);
        m_A[i][i]=-1;
    }

    var m_b=[];
    for(var i=0;i<12;i++)
        m_b[i]=-1;

    var m_beq=[];
     for(var i=0;i<10;i++)
        m_beq[i]=0;

     var m_C=[];     
     for(var i=0;i<12;i++)
        m_C[i]=1;
var x=numeric.solveLP(m_C,m_A,m_b,m_Aeq,m_beq);
console.log(x.solution);

In each row of m_Aeq, there is a '1' and a '-1' and the rest of it is 0. Thus it should have a solution of [1,1,1,1,1,1,1,1,1,1,1,1]. But the solution  I get  only contains 0 and NaN, and the iteration time is 0.  Is this a bug? Or do I misunderstand something? Is there any way to solve this?

Thanks.

On Wednesday, July 12, 2017 at 11:10:57 AM UTC-4, sloisel wrote:
Hi,

You have to use the matrix A and vector b for everything. This is an example for minimizing x-y in (1<x<2 and 1<y<2):

On 12 July 2017 at 15:57, Yi <guo...@seas.upenn.edu> wrote:
For the linear programming function solveLP,  how can we set a upper bound and lower bound for the solution?  Like what the linprog function does in matlab, linprog(c, A,b,Aeq,beq, lb,ub), where lb and ub are the lower bound and upper bound.

--
You received this message because you are subscribed to the Google Groups "numericjs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numericjs+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Sébastien Loisel

unread,
Jul 29, 2017, 6:16:10 PM7/29/17
to nume...@googlegroups.com
Hi,

The matrix must have full rank.

Thanks

S

In each row of m_Aeq, there is a '1' and a '-1' and the rest of it should be 0. Thus it should have a solution of [1,1,1,1,1,1,1,1,1,1,1,1]. But the solution  I get  only contains 0 and NaN, and the iteration time is 0.  Is this a bug? Or do I misunderstand something? Is there any way to solve this?

Thanks.

On Wednesday, July 12, 2017 at 11:10:57 AM UTC-4, sloisel wrote:
Hi,

You have to use the matrix A and vector b for everything. This is an example for minimizing x-y in (1<x<2 and 1<y<2):

On 12 July 2017 at 15:57, Yi <guo...@seas.upenn.edu> wrote:
For the linear programming function solveLP,  how can we set a upper bound and lower bound for the solution?  Like what the linprog function does in matlab, linprog(c, A,b,Aeq,beq, lb,ub), where lb and ub are the lower bound and upper bound.

--
You received this message because you are subscribed to the Google Groups "numericjs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numericjs+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Sébastien Loisel
Assistant Professor
Department of Mathematics, Heriot-Watt University
Riccarton, EH14 4AS, United Kingdom
web: http://www.ma.hw.ac.uk/~loisel/
email: S.Loisel at hw.ac.uk
phone: +44 131 451 3234
fax: +44 131 451 3249

Reply all
Reply to author
Forward
0 new messages