Skip to content

Commit b3a2ed6

Browse files
committed
chore: simplify logic
1 parent cfef158 commit b3a2ed6

File tree

4 files changed

+3
-45
lines changed

4 files changed

+3
-45
lines changed

src/main/java/ai/timefold/solver/benchmarks/examples/tsp/domain/Domicile.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ public Domicile(long id) {
1313
super(id);
1414
}
1515

16-
@Override
17-
public Standstill getPreviousStandstill() {
18-
return null;
19-
}
20-
21-
@Override
22-
public long getDistanceFromPreviousStandstill() {
23-
return 0;
24-
}
25-
2616
@Override
2717
public long getDistanceToNextStandstill() {
2818
var next = getNextStandstill();

src/main/java/ai/timefold/solver/benchmarks/examples/tsp/domain/Standstill.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ public long getId() {
3737
return id;
3838
}
3939

40-
public abstract Standstill getPreviousStandstill();
41-
42-
public abstract long getDistanceFromPreviousStandstill();
43-
4440
public abstract long getDistanceToNextStandstill();
4541

4642
@InverseRelationShadowVariable(sourceVariableName = "previousStandstill")

src/main/java/ai/timefold/solver/benchmarks/examples/tsp/domain/Visit.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public void setLocation(Location location) {
3737
}
3838

3939
@PlanningVariable(graphType = PlanningVariableGraphType.CHAINED)
40-
@Override
4140
public Standstill getPreviousStandstill() {
4241
return previousStandstill;
4342
}
@@ -59,18 +58,6 @@ public void setDomicile(Domicile domicile) {
5958
// Complex methods
6059
// ************************************************************************
6160

62-
/**
63-
* @return a positive number, the distance multiplied by 1000 to avoid floating point arithmetic rounding errors
64-
*/
65-
@JsonIgnore
66-
@Override
67-
public long getDistanceFromPreviousStandstill() {
68-
if (previousStandstill == null) {
69-
return 0L;
70-
}
71-
return getDistanceFrom(previousStandstill);
72-
}
73-
7461
/**
7562
* @return a positive number, the distance multiplied by 1000 to avoid floating point arithmetic rounding errors
7663
*/

src/main/java/ai/timefold/solver/benchmarks/examples/tsp/optional/score/TspIncrementalScoreCalculator.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package ai.timefold.solver.benchmarks.examples.tsp.optional.score;
22

3-
import ai.timefold.solver.benchmarks.examples.tsp.domain.Domicile;
43
import ai.timefold.solver.benchmarks.examples.tsp.domain.Standstill;
54
import ai.timefold.solver.benchmarks.examples.tsp.domain.TspSolution;
65
import ai.timefold.solver.benchmarks.examples.tsp.domain.Visit;
@@ -9,14 +8,12 @@
98

109
public class TspIncrementalScoreCalculator implements IncrementalScoreCalculator<TspSolution, SimpleLongScore> {
1110

12-
private Domicile domicile;
13-
1411
private long score;
1512

1613
@Override
1714
public void resetWorkingSolution(TspSolution tspSolution) {
18-
domicile = tspSolution.getDomicile();
1915
score = 0L;
16+
insert(tspSolution.getDomicile());
2017
for (Visit visit : tspSolution.getVisitList()) {
2118
insert(visit);
2219
}
@@ -53,23 +50,11 @@ public void afterEntityRemoved(Object entity) {
5350
}
5451

5552
private void insert(Standstill visit) {
56-
Standstill previousStandstill = visit.getPreviousStandstill();
57-
if (previousStandstill != null) {
58-
score -= visit.getDistanceFromPreviousStandstill();
59-
// HACK: This counts too much, but the insert/retracts balance each other out
60-
score += previousStandstill.getDistanceTo(domicile);
61-
score -= visit.getDistanceTo(domicile);
62-
}
53+
score -= visit.getDistanceToNextStandstill();
6354
}
6455

6556
private void retract(Standstill visit) {
66-
Standstill previousStandstill = visit.getPreviousStandstill();
67-
if (previousStandstill != null) {
68-
score += visit.getDistanceFromPreviousStandstill();
69-
// HACK: This counts too much, but the insert/retracts balance each other out
70-
score -= previousStandstill.getDistanceTo(domicile);
71-
score += visit.getDistanceTo(domicile);
72-
}
57+
score += visit.getDistanceToNextStandstill();
7358
}
7459

7560
@Override

0 commit comments

Comments
 (0)