-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimplexExample.java
More file actions
86 lines (65 loc) · 2.59 KB
/
SimplexExample.java
File metadata and controls
86 lines (65 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.alibaba.alink.devp;
import com.alibaba.alink.common.MLEnvironmentFactory;
import com.alibaba.alink.common.linalg.DenseVector;
import com.alibaba.alink.common.linalg.SparseVector;
import com.alibaba.alink.operator.batch.BatchOperator;
import org.apache.flink.types.Row;
import java.util.ArrayList;
public class SimplexExample {
public void test2() throws Exception{
Row[] rows1 = new Row[]{
Row.of(-3.0, 1.0, "le", 6.0),
Row.of(1.0, 2.0, "le", 4.0),
};
ArrayList<Double> objective = new ArrayList<>();
objective.add(-1.0);
objective.add(4.0);
SparseVector lowerBounds = new SparseVector(1);
lowerBounds.set(1, -3);
Integer[] unbounded = new Integer[1];
unbounded[0] = 0;
BatchOperator data = BatchOperator
.fromTable(MLEnvironmentFactory
.getDefault()
.createBatchTable(rows1, new String[]{"x0", "x1", "relation", "b"}));
LPSimplexBatchOp dOp = new LPSimplexBatchOp();
dOp.setObjective(objective)
.setLowerBounds(lowerBounds)
.setUnbounded(unbounded)
.setN(3)
.setMaxIter(10)
.setParallelism(3);
dOp.linkFrom(data).print();
}
public void test1() throws Exception {
Row[] rows1 = new Row[]{
Row.of(1.0, -2.0, 1.0, "le", 11.0),
Row.of(-4.0, 1.0, 2.0, "ge", 3.0),
Row.of(-2.0, 0.0, 1.0, "eq", 1.0),
};
ArrayList<Double> objective = new ArrayList<>();
objective.add(-3.0);
objective.add(1.0);
objective.add(1.0);
SparseVector lowerBounds = new SparseVector(1);
lowerBounds.set(1, -3);
Integer[] unbounded = new Integer[1];
unbounded[0] = 0;
BatchOperator data = BatchOperator
.fromTable(MLEnvironmentFactory
.getDefault()
.createBatchTable(rows1, new String[]{"x0", "x1", "x2", "relation", "b"}));
LPSimplexBatchOp dOp = new LPSimplexBatchOp();
dOp.setObjective(objective)
//.setLowerBounds(lowerBounds)
//.setUnbounded(unbounded)
.setN(3)
.setMaxIter(10)
.setParallelism(3);
dOp.linkFrom(data).print();
}
public static void main(String[] args) throws Exception {
SimplexExample readExample = new SimplexExample();
readExample.test1();
}
}