Skip to content

Commit

Permalink
refactor to a simpler model: delete BusVisit and BusStartPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0ffrey committed Apr 5, 2015
1 parent 82c0d06 commit cd6f71b
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
Coach.class,
Shuttle.class
})
public abstract class Bus extends AbstractPersistable {
public abstract class Bus extends AbstractPersistable implements BusOrStop {

protected String name;
protected RoadLocation departureLocation;
protected int capacity;
protected int mileageCost;

// Shadow variables
protected BusStop nextStop;

public String getName() {
return name;
}
Expand Down Expand Up @@ -65,10 +68,34 @@ public void setMileageCost(int mileageCost) {
this.mileageCost = mileageCost;
}

@Override
public BusStop getNextStop() {
return nextStop;
}

@Override
public void setNextStop(BusStop nextStop) {
this.nextStop = nextStop;
}

// ************************************************************************
// Complex methods
// ************************************************************************

public abstract int getSetupCost();

@Override
public RoadLocation getLocation() {
return departureLocation;
}

@Override
public Bus getBus() {
return this;
}

public abstract int getDistanceFromTo(RoadLocation sourceLocation, RoadLocation targetLocation);

@Override
public String toString() {
return name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.optaplanner.examples.common.domain.AbstractPersistable;

@XStreamAlias("CsgBusHub")
public class BusHub extends AbstractPersistable {
public class BusHub extends AbstractPersistable implements StopOrHub {

protected String name;
protected RoadLocation location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.optaplanner.examples.coachshuttlegathering.domain.location.RoadLocation;

@PlanningEntity
public interface BusStandstill {
public interface BusOrStop {

/**
* @return never null
Expand All @@ -31,13 +31,13 @@ public interface BusStandstill {
/**
* @return sometimes null
*/
BusStartPoint getStartPoint();
Bus getBus();

/**
* @return sometimes null
*/
@InverseRelationShadowVariable(sourceVariableName = "previousStandstill")
BusVisit getNextVisit();
void setNextVisit(BusVisit nextVisit);
@InverseRelationShadowVariable(sourceVariableName = "previousBusOrStop")
BusStop getNextStop();
void setNextStop(BusStop nextStop);

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,30 @@
package org.optaplanner.examples.coachshuttlegathering.domain;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import org.optaplanner.core.api.domain.entity.PlanningEntity;
import org.optaplanner.core.api.domain.variable.AnchorShadowVariable;
import org.optaplanner.core.api.domain.variable.PlanningVariable;
import org.optaplanner.core.api.domain.variable.PlanningVariableGraphType;
import org.optaplanner.examples.coachshuttlegathering.domain.location.RoadLocation;
import org.optaplanner.examples.coachshuttlegathering.domain.solver.DepotAngleBusStopDifficultyWeightFactory;
import org.optaplanner.examples.common.domain.AbstractPersistable;

@PlanningEntity(difficultyWeightFactoryClass = DepotAngleBusStopDifficultyWeightFactory.class)
@XStreamAlias("CsgBusStop")
public class BusStop extends AbstractPersistable {
public class BusStop extends AbstractPersistable implements BusOrStop, StopOrHub {

protected String name;
protected RoadLocation location;
protected int passengerQuantity;
protected int transportTimeLimit;

// Planning variables: changes during planning, between score calculations.
protected BusOrStop previousBusOrStop;

// Shadow variables
protected BusStop nextStop;
protected Bus bus;

public String getName() {
return name;
}
Expand All @@ -36,6 +49,7 @@ public void setName(String name) {
this.name = name;
}

@Override
public RoadLocation getLocation() {
return location;
}
Expand All @@ -59,10 +73,52 @@ public int getTransportTimeLimit() {
public void setTransportTimeLimit(int transportTimeLimit) {
this.transportTimeLimit = transportTimeLimit;
}

@PlanningVariable(valueRangeProviderRefs = {"coachRange", "shuttleRange", "stopRange"},
graphType = PlanningVariableGraphType.CHAINED)
public BusOrStop getPreviousBusOrStop() {
return previousBusOrStop;
}

public void setPreviousBusOrStop(BusOrStop previousBusOrStop) {
this.previousBusOrStop = previousBusOrStop;
}

@Override
public BusStop getNextStop() {
return nextStop;
}

@Override
public void setNextStop(BusStop nextStop) {
this.nextStop = nextStop;
}

@AnchorShadowVariable(sourceVariableName = "previousBusOrStop")
@Override
public Bus getBus() {
return bus;
}

public void setBus(Bus bus) {
this.bus = bus;
}

// ************************************************************************
// Complex methods
// ************************************************************************

public int getDistanceFromPreviousCost() {
if (previousBusOrStop == null) {
return 0;
}
return getDistanceFrom(previousBusOrStop) * bus.getMileageCost();
}

public int getDistanceFrom(BusOrStop busOrStop) {
return bus.getDistanceFromTo(busOrStop.getLocation(), location);
}

@Override
public String toString() {
return name;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.optaplanner.examples.coachshuttlegathering.domain;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import org.optaplanner.examples.coachshuttlegathering.domain.location.RoadLocation;
import org.optaplanner.examples.common.domain.AbstractPersistable;

@XStreamAlias("CsgCoach")
Expand All @@ -36,4 +37,14 @@ public void setStopLimit(int stopLimit) {
// Complex methods
// ************************************************************************

@Override
public int getSetupCost() {
return 0;
}

@Override
public int getDistanceFromTo(RoadLocation sourceLocation, RoadLocation targetLocation) {
return sourceLocation.getCoachDistanceTo(targetLocation);
}

}

0 comments on commit cd6f71b

Please sign in to comment.