Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DoubleLPConstraintSequence |
|
| 1.2;1,2 |
1 | /* | |
2 | This file is part of Combean. | |
3 | ||
4 | Combean is free software; you can redistribute it and/or modify | |
5 | it under the terms of the GNU General Public License as published by | |
6 | the Free Software Foundation; either version 2 of the License, or | |
7 | (at your option) any later version. | |
8 | ||
9 | Combean is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along with Combean; if not, write to the Free Software | |
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | */ | |
18 | /* | |
19 | * Created on 03.09.2005 | |
20 | * | |
21 | */ | |
22 | package net.sourceforge.combean.mathprog.lp.model; | |
23 | ||
24 | import net.sourceforge.combean.interfaces.mathprog.lp.LPConstraint; | |
25 | import net.sourceforge.combean.interfaces.mathprog.lp.model.LPConstraintSequence; | |
26 | import net.sourceforge.combean.mathprog.lp.DoubleLPConstraint; | |
27 | ||
28 | /** | |
29 | * A simple implementation of a constraint sequence, consisting of | |
30 | * DoubleLPConstraints. | |
31 | * | |
32 | * @author schickin | |
33 | * | |
34 | */ | |
35 | public class DoubleLPConstraintSequence extends AbstractLPConstraintSequence | |
36 | implements LPConstraintSequence { | |
37 | ||
38 | 24 | private LPConstraint[] constraints = null; |
39 | ||
40 | /** | |
41 | * Constructor for a sequence of undefined constraints (all elements are | |
42 | * initialized to null) | |
43 | * | |
44 | * @param length the length of the sequence to be constructed. | |
45 | */ | |
46 | public DoubleLPConstraintSequence(String offsetId, int length) { | |
47 | 0 | super(offsetId); |
48 | ||
49 | 0 | this.constraints = new LPConstraint[length]; |
50 | 0 | } |
51 | ||
52 | /** | |
53 | * Constructor for a constraint sequence with a uniform relation symbol. | |
54 | * | |
55 | * @param relation the uniform relation symbol. | |
56 | * @param rhs an array containing the right-hand side of all constraints | |
57 | * in the sequence. | |
58 | */ | |
59 | public DoubleLPConstraintSequence(String offsetId, | |
60 | byte relation, double[] rhs) { | |
61 | 24 | super(offsetId); |
62 | ||
63 | 24 | this.constraints = new LPConstraint[rhs.length]; |
64 | ||
65 | 96 | for (int i = 0; i < rhs.length; i++) { |
66 | 72 | this.constraints[i] = |
67 | new DoubleLPConstraint(offsetId + i, relation, rhs[i]); | |
68 | } | |
69 | 24 | } |
70 | ||
71 | /* (non-Javadoc) | |
72 | * @see net.sourceforge.combean.interfaces.mathprog.lp.model.LPConstraintSequence#getLPConstraint(int) | |
73 | */ | |
74 | public LPConstraint getLPConstraint(int localRow) { | |
75 | 72 | return this.constraints[localRow]; |
76 | } | |
77 | ||
78 | /* (non-Javadoc) | |
79 | * @see net.sourceforge.combean.interfaces.mathprog.lp.model.LPConditionSequence#getLength() | |
80 | */ | |
81 | public int getNumConstrs() { | |
82 | 60 | return this.constraints.length; |
83 | } | |
84 | ||
85 | /** | |
86 | * Set an individual LP constraint in the sequence. | |
87 | * | |
88 | * @param localRow the index of the LP constraint to be set. | |
89 | * @param value the value to set. | |
90 | */ | |
91 | public void setLPConstraint(int localRow, LPConstraint value) { | |
92 | 0 | this.constraints[localRow] = value; |
93 | 0 | } |
94 | } |