| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package net.sourceforge.combean.test.mathprog.grooml; |
| 19 | |
|
| 20 | |
import net.sourceforge.combean.mathprog.grooml.GLPModel; |
| 21 | |
import net.sourceforge.combean.mathprog.grooml.GVariables; |
| 22 | |
import net.sourceforge.combean.mathprog.grooml.GRows; |
| 23 | |
import net.sourceforge.combean.mathprog.grooml.GSet; |
| 24 | |
|
| 25 | |
class TestGLPModel extends GroovyTestCase { |
| 26 | |
|
| 27 | |
private GLPModel lpModel; |
| 28 | |
private GVariables lpVars; |
| 29 | |
private GRows lpRows; |
| 30 | |
|
| 31 | |
private static final double[] coeff = [4.0, 10.0]; |
| 32 | |
private static final double[] rhs = [2.0, 2.0, 10.0]; |
| 33 | |
|
| 34 | |
void setUp() { |
| 35 | 12 | this.lpModel = new GLPModel(); |
| 36 | 12 | this.lpVars = new GVariables("x", 0..(coeff.length-1), [:]) { |
| 37 | 6 | [coeff[it], 0..Double.POSITIVE_INFINITY] |
| 38 | |
} |
| 39 | 12 | this.lpRows = new GRows("row", 0..2, this.lpModel, [:]) { |
| 40 | 9 | ["x[${it % 2}]", "<= ${rhs[it]}"] |
| 41 | |
} |
| 42 | |
} |
| 43 | |
|
| 44 | |
void testAddAndGetVariables() { |
| 45 | 3 | assertEquals(0, this.lpModel.numColumns); |
| 46 | 3 | this.lpModel.addVariables(this.lpVars); |
| 47 | 3 | assertEquals(coeff.length, this.lpModel.numColumns); |
| 48 | 3 | GVariables vars = this.lpModel.getVariables("x"); |
| 49 | 3 | assertEquals(this.lpVars, vars); |
| 50 | |
} |
| 51 | |
|
| 52 | |
void testAddConstraints() { |
| 53 | 3 | assertEquals(0, this.lpModel.numRows); |
| 54 | 3 | this.lpModel.addConstraints(this.lpRows); |
| 55 | 3 | assertEquals(rhs.length, this.lpModel.numRows); |
| 56 | |
} |
| 57 | |
|
| 58 | |
void testAddRows() { |
| 59 | 3 | assertEquals(0, this.lpModel.numRows); |
| 60 | 3 | this.lpModel.addRows(this.lpRows); |
| 61 | 3 | assertEquals(rhs.length, this.lpModel.numRows); |
| 62 | |
} |
| 63 | |
|
| 64 | |
void testSummaryString() { |
| 65 | 3 | this.lpModel.addVariables(this.lpVars); |
| 66 | 3 | this.lpModel.addRows(this.lpRows); |
| 67 | 3 | assertEquals(""" |
| 68 | |
vars x[4.0, 10.0] |
| 69 | |
row: |
| 70 | |
1.0 x[0] <= 2.0 |
| 71 | |
1.0 x[1] <= 2.0 |
| 72 | |
1.0 x[0] <= 10.0 |
| 73 | 3 | """, this.lpModel.toSummaryString()); |
| 74 | |
} |
| 75 | |
} |