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: glpk xypron
Subject: Re: [Help-glpk] implementing constraints in Scala
Date: Thu, 28 Jul 2011 18:29:52 +0200

Dear Onor,

the relevant API information is in file
glpk-4.45\doc\glpk.pdf
of the GLPK source documentation.

When you have n columns, you will need to call
glp_set_mat_row() with arrays of size n+1,
because index 0 is not used.

GLPK.new_intArray(n) creates an array with indices
0 .. n-1. Same is true for GLPK.new_doubleArray(n).

Hence, please, change your statements to
val ind = GLPK.new_intArray(col.size + 1);
val values = GLPK.new_doubleArray(col.size + 1);

Best regards

Xypron

-------- Original-Nachricht --------
> Datum: Thu, 28 Jul 2011 11:59:48 +0200
> Betreff: [Help-glpk] implementing contrants in Scala

> I would like to implment glpk in scala.
> 
>     def addConstraintLessEqual(coef : Array[Double], col : Array[Int], rhs
> :
> Double) {
>  nbRows += 1
>         GLPK.glp_add_rows(lp, 1);
>         GLPK.glp_set_row_name(lp, 1, "constraint"+nbRows);
>         GLPK.glp_set_row_bnds(lp, 1, GLPKConstants.GLP_UP, rhs, 0)
>         val ind = GLPK.new_intArray(col.size)
>         for (i <- 1 to col.size) {
>           GLPK.intArray_setitem(ind, i, col(i-1)+1);
>         }
>         val values = GLPK.new_doubleArray(col.size);
>         for (i <- 1 to col.size) {
>           GLPK.doubleArray_setitem(values, col(i-1)+1, coef(i-1));
>         }
>         GLPK.glp_set_mat_row(lp, nbRows, col.size, ind, values)
>         println("addConstraintLessEqual: end");
>     }
> 
> 
> 
> could you tell me where is the problem ?

-- 
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]