1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
package net.sourceforge.combean.mathprog.lp.model; |
6 | |
|
7 | |
import net.sourceforge.combean.interfaces.mathprog.linalg.SparseVector; |
8 | |
import net.sourceforge.combean.interfaces.mathprog.linalg.VectorIterator; |
9 | |
import net.sourceforge.combean.interfaces.mathprog.linalg.VectorOrientation; |
10 | |
import net.sourceforge.combean.interfaces.mathprog.linalg.VectorValue; |
11 | |
import net.sourceforge.combean.interfaces.mathprog.lp.model.LPSparseVector; |
12 | |
import net.sourceforge.combean.interfaces.mathprog.lp.model.LPVectorLabel; |
13 | |
import net.sourceforge.combean.interfaces.mathprog.lp.model.NoLabel; |
14 | |
import net.sourceforge.combean.mathprog.linalg.DoubleVectorValue; |
15 | |
|
16 | |
public class SparseVectorAsLPVector |
17 | |
implements LPSparseVector { |
18 | |
|
19 | |
protected LPVectorLabelImpl label; |
20 | |
private SparseVector wrappedVec; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
public SparseVectorAsLPVector(SparseVector wrappedVec, |
26 | |
String offsetId, VectorOrientation orientation) { |
27 | 240 | super(); |
28 | 240 | this.wrappedVec = wrappedVec; |
29 | 240 | this.label = new LPVectorLabelImpl(offsetId, orientation); |
30 | 240 | } |
31 | |
|
32 | |
public int getDimension() { |
33 | 0 | return this.wrappedVec.getDimension(); |
34 | |
} |
35 | |
|
36 | |
public VectorIterator<LPVectorLabel> iterator() { |
37 | 240 | return new VectorIteratorAsLPVectorIterator( |
38 | |
this.wrappedVec.iterator()); |
39 | |
} |
40 | |
|
41 | |
public int getNumIterations() { |
42 | 240 | return this.wrappedVec.getNumIterations(); |
43 | |
} |
44 | |
|
45 | |
public String toString() { |
46 | 0 | return "sparseVec { label {" + this.label + "}" + |
47 | |
" svec {" + this.wrappedVec + "} }"; |
48 | |
} |
49 | |
|
50 | 486 | private class VectorIteratorAsLPVectorIterator |
51 | |
implements VectorIterator<LPVectorLabel> { |
52 | |
|
53 | |
private VectorIterator<NoLabel> wrappedIt; |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public VectorIteratorAsLPVectorIterator( |
59 | 240 | VectorIterator<NoLabel> wrappedIt) { |
60 | 240 | super(); |
61 | 240 | this.wrappedIt = wrappedIt; |
62 | 240 | } |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public VectorValue<LPVectorLabel> next() { |
68 | 486 | VectorValue<NoLabel> wrappedVal = this.wrappedIt.next(); |
69 | 486 | return new DoubleVectorValue<LPVectorLabel>( |
70 | |
wrappedVal.index(), wrappedVal.doubleValue(), |
71 | |
SparseVectorAsLPVector.this.label); |
72 | |
} |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
public boolean hasNext() { |
78 | 726 | return this.wrappedIt.hasNext(); |
79 | |
} |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
public void remove() { |
85 | 0 | this.wrappedIt.remove(); |
86 | 0 | } |
87 | |
|
88 | |
} |
89 | |
|
90 | |
} |