-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClTestColumns.java
113 lines (87 loc) · 3.19 KB
/
ClTestColumns.java
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// $Id$
//
// Cassowary Incremental Constraint Solver
// Original Smalltalk Implementation by Alan Borning
// This Java Implementation by Greg J. Badros, <[email protected]>
// http://www.cs.washington.edu/homes/gjb
// (C) 1998, 1999 Greg J. Badros and Alan Borning
// See ../LICENSE for legal details regarding this software
//
// ClTestColumns.java
package EDU.Washington.grad.gjb.cassowary;
import java.lang.*;
import java.util.Random;
class ClTestColumns extends CL {
public final static boolean addDelete1()
throws ExCLInternalError, ExCLRequiredFailure, ExCLConstraintNotFound
{
boolean fOkResult = true;
ClVariable x = new ClVariable("x");
ClSimplexSolver solver = new ClSimplexSolver();
solver.addConstraint( new ClLinearEquation( x, 100, ClStrength.weak ) );
ClLinearInequality c10 = new ClLinearInequality(x,CL.LEQ,10.0);
ClLinearInequality c20 = new ClLinearInequality(x,CL.LEQ,20.0);
solver
.addConstraint(c10)
.addConstraint(c20);
fOkResult = fOkResult && CL.approx(x,10.0);
System.out.println("x == " + x.value());
solver.removeConstraint(c10);
fOkResult = fOkResult && CL.approx(x,20.0);
System.out.println("x == " + x.value());
solver.removeConstraint(c20);
fOkResult = fOkResult && CL.approx(x,100.0);
System.out.println("x == " + x.value());
ClLinearInequality c10again = new ClLinearInequality(x,CL.LEQ,10.0);
solver
.addConstraint(c10)
.addConstraint(c10again);
fOkResult = fOkResult && CL.approx(x,10.0);
System.out.println("x == " + x.value());
solver.removeConstraint(c10);
fOkResult = fOkResult && CL.approx(x,10.0);
System.out.println("x == " + x.value());
solver.removeConstraint(c10again);
fOkResult = fOkResult && CL.approx(x,100.0);
System.out.println("x == " + x.value());
System.err.println("Solver == " + solver);
return(fOkResult);
}
public final static boolean reqFail1()
throws ExCLInternalError, ExCLRequiredFailure, ExCLConstraintNotFound
{
boolean fOkResult = true;
ClVariable x = new ClVariable("x");
ClSimplexSolver solver = new ClSimplexSolver();
for (int i = 100; i < 900; i += 100) {
try {
solver.addConstraint( new ClLinearEquation( x, i, ClStrength.required ) );
} catch (Exception e) {
// do nothing
}
}
System.out.println("x == " + x.value());
System.err.println("Solver == " + solver);
return(fOkResult);
}
public final static void main( String[] args )
throws ExCLInternalError, ExCLNonlinearExpression,
ExCLRequiredFailure, ExCLConstraintNotFound
{
// try
{
boolean fAllOkResult = true;
boolean fResult;
System.out.println("addDelete1:");
fResult = addDelete1(); fAllOkResult &= fResult;
fResult = reqFail1(); fAllOkResult &= fResult;
if (!fResult) System.out.println("Failed!");
if (CL.fGC) System.out.println("Num vars = " + ClAbstractVariable.numCreated() );
}
// catch (Exception err)
// {
// System.err.println("Exception: " + err);
// }
}
static private Random RND;
}