Skip to content

Commit bd2c063

Browse files
committed
v1.2.0: code and samples
1 parent 0899eb2 commit bd2c063

Some content is hidden

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

47 files changed

+6870
-202
lines changed

LICENSE

Lines changed: 168 additions & 201 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
1-
# easycsp-lib
1+
## EasyCSP is an open-source Java library for Constraint Satisfaction Programming.
2+
23
EasyCSP is an open-source Java library for Constraint Satisfaction Programming.
4+
5+
EasyCSP offers search algorithms for both CSPs and CSOPs.
6+
7+
EasyCSP supports CSPs to be formalized using objects or int expressions.
8+
9+
10+
### Dependencies
11+
12+
Requires Java 8 or later.
13+
14+
### Release Notes
15+
16+
!Release 1.2.0
17+
- fix: IntDomain size() bug when containing both positive and negative ints.
18+
- feature: added int specific model classes, constraint expressions API and
19+
specialized search algorithm.
20+

easycsp/src-samples/.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

easycsp/src-samples/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

easycsp/src-samples/.idea/workspace.xml

Lines changed: 485 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

easycsp/src-samples/KnightTour.png

353 KB
Loading

easycsp/src-samples/Semaphore.png

10.4 KB
Loading

easycsp/src-samples/Sudoku.png

20.8 KB
Loading
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2011 Victor Cordis
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Please contact the author ( [email protected] ) if you need additional
17+
* information or have any questions.
18+
*/
19+
package net.sourceforge.easycsp.sample.jobscheduling;
20+
21+
import net.sourceforge.easycsp.*;
22+
import net.sourceforge.easycsp.Algorithm.Fitness;
23+
import net.sourceforge.easycsp.alg.BranchAndBound;
24+
25+
public class FlowtimeMain {
26+
27+
/**
28+
* FlowtimeMain.main method solves the formal JobScheduling CSOP( Z, D , C):
29+
* 5 Machines and 5 Jobs (for assigning more than one Job per Machine, the
30+
* domain must contain arrays of Jobs)
31+
*/
32+
public static void main(String[] args) {
33+
// create CSP(Z,D,C):
34+
Machine[] machines = new Machine[]{
35+
new Machine(0, 3),
36+
new Machine(1, 12),
37+
new Machine(2, 8),
38+
new Machine(3, 6),
39+
new Machine(4, 7)
40+
};
41+
Domain<Job> domain = new ObjectDomain<>(new Job(0, 3), new Job(1, 6), new Job(2, 5), new Job(3, 10), new Job(4, 9));
42+
43+
EasyCSP flowtime = EasyCSPBuilder.of("Flowtime", domain, machines)
44+
.constrainEachTwo(Constraints.notEqual())
45+
.build();
46+
47+
Fitness<Machine, Job> estimation = (s, idx, score) -> {
48+
if (idx == 0) {
49+
double totalEstim = s.value(0).getOperationCount() / s.variable(0).get().getExecutionSpeed();
50+
for (int i = 1; i < s.size(); i++) {
51+
// estimate the best case: the job with smallest OperationCount / Machine ExecutionSpeed:
52+
Variable<Machine, Job> v = s.variable(i);
53+
totalEstim += v.getDomain().get(0).getOperationCount() / v.get().getExecutionSpeed();
54+
}
55+
return totalEstim;
56+
} else {
57+
Variable<Machine, Job> v = s.variable(idx);
58+
// undo last estimation:
59+
double time = score - (v.getDomain().get(0).getOperationCount() / v.get().getExecutionSpeed());
60+
// add the last element:
61+
return time + (s.value(idx).getOperationCount() / v.get().getExecutionSpeed());
62+
}
63+
};
64+
Fitness<Machine, Job> evaluation = (s, idx, score) ->
65+
{
66+
Variable<Machine, Job> v = s.variable(idx);
67+
// undo last estimation:
68+
double time = score - (v.getDomain().get(0).getOperationCount() / v.get().getExecutionSpeed());
69+
// add the last element:
70+
return time + (s.value(idx).getOperationCount() / v.get().getExecutionSpeed());
71+
};
72+
73+
// solve:
74+
BranchAndBound alg = BranchAndBound.minimizationOf(flowtime, estimation, evaluation);
75+
Solver solver = new Solver(alg);
76+
while (solver.solve()) {
77+
System.out.println(solver.getSolutionCount() + " " + solver.currentSolution() + ", Flowtime= " + alg.evaluation());
78+
}
79+
System.out.println(solver.getSolutionCount() + " optimal solution(s) in " + solver.getElapsedTime() / 1000.00 + " seconds");
80+
}
81+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2011 Victor Cordis
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Please contact the author ( [email protected] ) if you need additional
17+
* information or have any questions.
18+
*/
19+
package net.sourceforge.easycsp.sample.jobscheduling;
20+
21+
public class Job {
22+
23+
private int id;
24+
private int operationCount;
25+
26+
27+
public Job(int id, int operationcount){
28+
this.id = id;
29+
this.operationCount= operationcount;
30+
}
31+
32+
public int getId(){
33+
return this.id;
34+
}
35+
36+
public int getOperationCount(){
37+
return this.operationCount;
38+
}
39+
40+
@Override
41+
public boolean equals(Object o){
42+
if( o instanceof Job){
43+
Job j=(Job) o;
44+
return this.id == j.id;
45+
}
46+
return false;
47+
}
48+
49+
@Override
50+
public String toString(){
51+
return "J(" + this.id + "," + this.operationCount + ")";
52+
}
53+
54+
}//class Job.

0 commit comments

Comments
 (0)