help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-glpk] implementing constraints in Scala


From: name name
Subject: Re: [Help-glpk] implementing constraints in Scala
Date: Mon, 1 Aug 2011 10:26:44 +0200

How can I print hole model, objective + constrains ?
Set the uper bount to infinity and get uper/lower bount of a variable?

On Sun, Jul 31, 2011 at 6:58 PM, glpk xypron <address@hidden> wrote:
Hello Onor,

>>        for (i <- 0 to col.size-1) {
>>          GLPK.glp_set_obj_coef(lp, i,coef(i))
>>        }
if you have n columns, GLPK number these 1 to n. You possibly
wanted to write:
         GLPK.glp_set_obj_coef(lp, i + 1,coef(i))

Cf. sample.c on page 15 of glpk-4.45/doc/glpk.pdf

>>       GLPK.glp_set_col_bnds(lp, colId+1, GLPKConstants.GLP_LO, 0,1000)
The number 1000 will be ignored.
The lower bound will be set to 0.

Best regards

Xypron

-------- Original-Nachricht --------
> Datum: Sun, 31 Jul 2011 16:07:01 +0200
> Betreff: Re: [Help-glpk] implementing constraints in Scala

> thank you very much I have some more question
>
> there is a problem I got no solution and i dont knew why.
>
> Could you tell me in which function(s) is the problem?
>
> the contraints I did as you told me. I change only GLP_UP; FX
>
>
> startModelBuilding(nbRows : Int, nbCols : Int){
> lp = GLPK.glp_create_prob()
>         GLPK.glp_add_cols(lp, nbCols)
> }
>
>       def setBounds(colId : Int, low : Double, up : Double) {
>         GLPK.glp_set_col_bnds(lp, colId+1, GLPKConstants.GLP_DB, low, up)
>       }
>
>       def setUnboundUpperBound(colId : Int) {
>       GLPK.glp_set_col_bnds(lp, colId+1, GLPKConstants.GLP_LO, 0,1000)
>       }
>
>     def addObjective(coef : Array[Double], col : Array[Int], minMode :
> Boolean = true) {
>         GLPK.glp_set_obj_name(lp, "objective");
>         GLPK.glp_set_obj_dir(lp, if (minMode) GLPKConstants.GLP_MIN else
> GLPKConstants.GLP_MAX)
>         for (i <- 0 to col.size-1) {
>           GLPK.glp_set_obj_coef(lp, i,coef(i))
>         }
>     }
>
>     def solveModel() : Int = {
>       println("solveModel");
>         val iocp = new glp_iocp();
>         GLPK.glp_init_iocp(iocp);
>         iocp.setPresolve(
> GLPKConstants.GLP_ON);
>         val ret = GLPK.glp_intopt(lp, iocp);
>
>         if (ret == 0) {
>           sol = Array.tabulate(nbCols)(col => GLPK.glp_mip_col_val(lp,col
> +1))
>           objectiveValue = GLPK.glp_mip_obj_val(lp)
>
>           ret
>         } else {
>             System.out.println("The problem could not be solved");
>             ret

--
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de


reply via email to

[Prev in Thread] Current Thread [Next in Thread]