Skip to content

Commit c2a8cc6

Browse files
committed
v1.3.1: refactor API and perf
1 parent 3ef4b5d commit c2a8cc6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1082
-859
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ EasyCSP is an open-source Java library for Constraint Satisfaction Programming.
44

55
EasyCSP offers search algorithms for both CSPs and CSOPs.
66

7-
EasyCSP supports CSPs to be formalized using objects or int expressions.
7+
EasyCSP supports CSPs to be defined using objects or int expressions.
88

99

1010
### Dependencies
@@ -13,11 +13,16 @@ EasyCSP supports CSPs to be formalized using objects or int expressions.
1313

1414
### Release Notes
1515

16-
!Release 1.2.1
16+
Release 1.3.1
17+
- refactored: Solution API and generics in general.
18+
- performance: avoid int-Integer autoboxing for int CSPs.
19+
- fix: int expression binarization issue.
20+
21+
Release 1.2.1
1722
- fix: ConflictMinimizing search algorithm bug.
1823
- feature: added full support (algorithms and API) for int specific CSPs and CSOPs.
1924

20-
!Release 1.2.0
25+
Release 1.2.0
2126
- fix: IntDomain size() bug when containing both positive and negative ints.
2227
- feature: added int specific model classes, constraint expressions API and
2328
specialized search algorithm.
File renamed without changes.
File renamed without changes.
File renamed without changes.

easycsp/src-samples/net/sourceforge/easycsp/sample/jobscheduling/FlowtimeMain.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package net.sourceforge.easycsp.sample.jobscheduling;
2020

2121
import net.sourceforge.easycsp.*;
22-
import net.sourceforge.easycsp.Algorithm.Fitness;
2322
import net.sourceforge.easycsp.alg.BranchAndBound;
2423

2524
import static net.sourceforge.easycsp.Constraints.notEqual;
@@ -34,19 +33,19 @@ public class FlowtimeMain {
3433
public static void main(String[] args) {
3534
// create CSP(Z,D,C):
3635
EasyCSP flowtime = EasyCSPBuilder.of("Flowtime",
37-
new ObjectDomain<>(
38-
new Job(0, 3),
39-
new Job(1, 6),
40-
new Job(2, 5),
41-
new Job(3, 10),
42-
new Job(4, 9)),
43-
new Machine[]{
44-
new Machine(0, 3),
45-
new Machine(1, 12),
46-
new Machine(2, 8),
47-
new Machine(3, 6),
48-
new Machine(4, 7)
49-
})
36+
new ObjectDomain<>(
37+
new Job(0, 3),
38+
new Job(1, 6),
39+
new Job(2, 5),
40+
new Job(3, 10),
41+
new Job(4, 9)),
42+
new Machine[]{
43+
new Machine(0, 3),
44+
new Machine(1, 12),
45+
new Machine(2, 8),
46+
new Machine(3, 6),
47+
new Machine(4, 7)
48+
})
5049
.constrainEachTwo(notEqual())
5150
.build();
5251

@@ -59,7 +58,7 @@ public static void main(String[] args) {
5958
System.out.println(solver.getSolutionCount() + " optimal solution(s) in " + solver.getElapsedTime() / 1000.00 + " seconds");
6059
}
6160

62-
private static double estimate(Solution<Machine, Job> s, int idx, double score) {
61+
private static double estimate(ObjectSolution<Machine, Job> s, int idx, double score) {
6362
if (idx == 0) {
6463
double totalEstim = s.value(0).getOperationCount() / s.variable(0).get().getExecutionSpeed();
6564
for (int i = 1; i < s.size(); i++) {
@@ -77,7 +76,7 @@ private static double estimate(Solution<Machine, Job> s, int idx, double score)
7776
}
7877
}
7978

80-
private static double evaluate(Solution<Machine, Job> s, int idx, double score) {
79+
private static double evaluate(ObjectSolution<Machine, Job> s, int idx, double score) {
8180
Variable<Machine, Job> v = s.variable(idx);
8281
// undo last estimation:
8382
double time = score - (v.getDomain().get(0).getOperationCount() / v.get().getExecutionSpeed());

easycsp/src-samples/net/sourceforge/easycsp/sample/jobscheduling/Job.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,31 @@ public class Job {
2424
private int operationCount;
2525

2626

27-
public Job(int id, int operationcount){
28-
this.id = id;
29-
this.operationCount= operationcount;
27+
public Job(int id, int operationcount) {
28+
this.id = id;
29+
this.operationCount = operationcount;
3030
}
3131

32-
public int getId(){
32+
public int getId() {
3333
return this.id;
3434
}
3535

36-
public int getOperationCount(){
36+
public int getOperationCount() {
3737
return this.operationCount;
3838
}
3939

4040
@Override
41-
public boolean equals(Object o){
42-
if( o instanceof Job){
43-
Job j=(Job) o;
41+
public boolean equals(Object o) {
42+
if (o instanceof Job) {
43+
Job j = (Job) o;
4444
return this.id == j.id;
4545
}
4646
return false;
4747
}
4848

4949
@Override
50-
public String toString(){
50+
public String toString() {
5151
return "J(" + this.id + "," + this.operationCount + ")";
5252
}
5353

54-
}//class Job.
54+
}

easycsp/src-samples/net/sourceforge/easycsp/sample/jobscheduling/Machine.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,35 @@
2020

2121
public class Machine {
2222

23-
private int id;
23+
private int id;
2424
private double executionSpeed;
2525

2626

27-
public Machine(int id, double executionspeed){
28-
this.id = id;
29-
this.executionSpeed= executionspeed;
27+
public Machine(int id, double executionspeed) {
28+
this.id = id;
29+
this.executionSpeed = executionspeed;
3030
}
3131

32-
public int getId(){
32+
public int getId() {
3333
return this.id;
3434
}
3535

36-
public double getExecutionSpeed(){
36+
public double getExecutionSpeed() {
3737
return this.executionSpeed;
3838
}
3939

4040
@Override
41-
public boolean equals(Object o){
42-
if( o instanceof Machine){
43-
Machine m=(Machine) o;
41+
public boolean equals(Object o) {
42+
if (o instanceof Machine) {
43+
Machine m = (Machine) o;
4444
return this.id == m.id;
4545
}
4646
return false;
4747
}
4848

4949
@Override
50-
public String toString(){
50+
public String toString() {
5151
return this.id + " " + this.executionSpeed;
5252
}
5353

54-
}//class Machine.
54+
}

easycsp/src-samples/net/sourceforge/easycsp/sample/jobscheduling/MakespanMain.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ public class MakespanMain {
3333
public static void main(String[] args) {
3434
// create CSP(Z,D,C):
3535
EasyCSP makespan = EasyCSPBuilder.of("Makespan",
36-
new ObjectDomain<>(
37-
new Job(0, 3),
38-
new Job(1, 6),
39-
new Job(2, 5),
40-
new Job(3, 10),
41-
new Job(4, 9)),
42-
new Machine[]{
43-
new Machine(0, 3),
44-
new Machine(1, 12),
45-
new Machine(2, 8),
46-
new Machine(3, 6),
47-
new Machine(4, 7)})
36+
new ObjectDomain<>(
37+
new Job(0, 3),
38+
new Job(1, 6),
39+
new Job(2, 5),
40+
new Job(3, 10),
41+
new Job(4, 9)),
42+
new Machine[]{
43+
new Machine(0, 3),
44+
new Machine(1, 12),
45+
new Machine(2, 8),
46+
new Machine(3, 6),
47+
new Machine(4, 7)})
4848
.constrainEachTwo(notEqual())
4949
.build();
5050

@@ -57,7 +57,7 @@ public static void main(String[] args) {
5757
System.out.println(solver.getSolutionCount() + " optimal solution(s) in " + solver.getElapsedTime() / 1000.00 + " seconds");
5858
}
5959

60-
private static double estimate(Solution<Machine, Job> s, int idx, double score) {
60+
private static double estimate(ObjectSolution<Machine, Job> s, int idx, double score) {
6161
double ret;
6262
if (idx == 0) {
6363
ret = s.value(0).getOperationCount() / s.variable(0).get().getExecutionSpeed();
@@ -78,7 +78,7 @@ private static double estimate(Solution<Machine, Job> s, int idx, double score)
7878
return ret > max ? ret : max;
7979
}
8080

81-
private static double evaluate(Solution<Machine, Job> s, int idx, double score) {
81+
private static double evaluate(ObjectSolution<Machine, Job> s, int idx, double score) {
8282
double max = Double.NEGATIVE_INFINITY;
8383
for (int i = 0; i < s.size(); i++) {
8484
double crtValue = s.value(i).getOperationCount() / s.variable(i).get().getExecutionSpeed();

easycsp/src-samples/net/sourceforge/easycsp/sample/knighttour/Cell.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ public class Cell {
2424
public final int y;
2525

2626

27-
public Cell(){
28-
this.x= -1;
29-
this.y= -1;
27+
public Cell() {
28+
this.x = -1;
29+
this.y = -1;
3030
}
3131

32-
public Cell(int x, int y){
33-
this.x= x;
34-
this.y= y;
32+
public Cell(int x, int y) {
33+
this.x = x;
34+
this.y = y;
3535
}
3636

3737
@Override
3838
public boolean equals(Object o) {
39-
if( o instanceof Cell){
40-
Cell c=(Cell) o;
39+
if (o instanceof Cell) {
40+
Cell c = (Cell) o;
4141
return this.x == c.x && this.y == c.y;
4242
}
4343
return false;
@@ -56,4 +56,4 @@ public String toString() {
5656
return "[" + this.x + "," + this.y + "]";
5757
}
5858

59-
}//class Cell.
59+
}

easycsp/src-samples/net/sourceforge/easycsp/sample/knighttour/Main.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
*/
1919
package net.sourceforge.easycsp.sample.knighttour;
2020

21-
import net.sourceforge.easycsp.*;
2221
import net.sourceforge.easycsp.Algorithm.Fitness;
22+
import net.sourceforge.easycsp.*;
2323
import net.sourceforge.easycsp.alg.Greedy;
2424

2525
import static net.sourceforge.easycsp.Constraints.is;
@@ -57,8 +57,8 @@ public static void main(String[] args) {
5757
System.out.println(s.getSolutionCount() + " solution in " + s.getElapsedTime() / 1000.00 + " seconds");
5858
}
5959

60-
private static Fitness<?, Cell> minDegree() {
61-
return new Fitness<Object, Cell>() {
60+
private static Fitness<ObjectSolution<Object, Cell>> minDegree() {
61+
return new Fitness<>() {
6262
private final boolean[][] used = new boolean[BOARD_SIZE][BOARD_SIZE];
6363

6464
private boolean isValid(int x, int y) {
@@ -72,7 +72,7 @@ private boolean isValid(int x, int y) {
7272
}
7373

7474
@Override
75-
public double compute(Solution<Object, Cell> sol, int variableIndex, double score) {
75+
public double compute(ObjectSolution<Object, Cell> sol, int variableIndex, double score) {
7676
if (variableIndex > 0) {
7777
Cell prev = sol.value(variableIndex - 1);
7878
this.used[prev.x][prev.y] = true;

0 commit comments

Comments
 (0)