List of usage examples for org.apache.commons.lang.builder CompareToBuilder CompareToBuilder
public CompareToBuilder()
Constructor for CompareToBuilder.
Starts off assuming that the objects are equal.
From source file:org.drools.planner.examples.parentalbenefit.domain.MonthPlan.java
public int compareTo(MonthPlan other) { return new CompareToBuilder().append(month, other.month).append(parent, other.parent).toComparison(); }
From source file:org.drools.planner.examples.parentalbenefit.domain.Parent.java
public int compareTo(Parent other) { return new CompareToBuilder().append(name, other.name).toComparison(); }
From source file:org.drools.planner.examples.parentalbenefit.domain.Settings.java
public int compareTo(Settings other) { return new CompareToBuilder().append(id, other.id).toComparison(); }
From source file:org.drools.planner.examples.parentalbenefit.domain.solver.ParentDaysAtHomeTotal.java
public int compareTo(ParentDaysAtHomeTotal other) { return new CompareToBuilder().append(parent, other.parent) .append(daysOnSicknessBenefit, other.daysOnSicknessBenefit) .append(daysOnMinimumBenefit, other.daysOnMinimumBenefit) .append(daysWithoutPay, other.daysWithoutPay).toComparison(); }
From source file:org.drools.planner.examples.pas.domain.solver.AdmissionPartConflict.java
public int compareTo(AdmissionPartConflict other) { return new CompareToBuilder().append(leftAdmissionPart, other.leftAdmissionPart) .append(rightAdmissionPart, other.rightAdmissionPart).toComparison(); }
From source file:org.drools.planner.examples.pas.domain.solver.AdmissionPartSpecialismMissingInRoom.java
public int compareTo(AdmissionPartSpecialismMissingInRoom other) { return new CompareToBuilder().append(admissionPart, other.admissionPart).append(room, other.room) .toComparison();/* w ww . jav a 2 s .c om*/ }
From source file:org.drools.planner.examples.pas.domain.solver.BedStrengthComparator.java
public int compare(Bed a, Bed b) { Room aRoom = a.getRoom();/*from w w w. ja v a2 s . c o m*/ Room bRoom = b.getRoom(); return new CompareToBuilder().append(bRoom.getCapacity(), aRoom.getCapacity()) // Descending (smaller rooms are stronger) .append(aRoom.getRoomEquipmentList().size() + aRoom.getRoomSpecialismList().size(), bRoom.getRoomEquipmentList().size() + bRoom.getRoomSpecialismList().size()) .append(a.getId(), b.getId()).toComparison(); }
From source file:org.drools.planner.examples.pas.solver.move.factory.BedDesignationPillarPartSwapMoveFactory.java
public List<Move> createMoveList(Solution solution) { PatientAdmissionSchedule patientAdmissionSchedule = (PatientAdmissionSchedule) solution; Map<Bed, List<BedDesignation>> bedToBedDesignationList = new HashMap<Bed, List<BedDesignation>>( patientAdmissionSchedule.getBedList().size()); for (BedDesignation bedDesignation : patientAdmissionSchedule.getBedDesignationList()) { List<BedDesignation> bedDesignationListPerBed = bedToBedDesignationList.get(bedDesignation.getBed()); if (bedDesignationListPerBed == null) { // Note: the initialCapacity is probably to high, // which is bad for memory, but the opposite is bad for performance (which is worse) bedDesignationListPerBed = new ArrayList<BedDesignation>( patientAdmissionSchedule.getNightList().size()); bedToBedDesignationList.put(bedDesignation.getBed(), bedDesignationListPerBed); }/*from w w w . java2 s .com*/ bedDesignationListPerBed.add(bedDesignation); } for (List<BedDesignation> bedDesignationListPerBed : bedToBedDesignationList.values()) { Collections.sort(bedDesignationListPerBed, new Comparator<BedDesignation>() { public int compare(BedDesignation a, BedDesignation b) { // This comparison is sameBedInSameNight safe. return new CompareToBuilder() .append(a.getAdmissionPart().getFirstNight(), b.getAdmissionPart().getFirstNight()) .append(a.getAdmissionPart().getLastNight(), b.getAdmissionPart().getLastNight()) .append(a.getAdmissionPart(), b.getAdmissionPart()).toComparison(); } }); } List<Bed> bedList = patientAdmissionSchedule.getBedList(); List<Move> moveList = new ArrayList<Move>(); // For every 2 distinct beds for (ListIterator<Bed> leftBedIt = bedList.listIterator(); leftBedIt.hasNext();) { Bed leftBed = leftBedIt.next(); for (ListIterator<Bed> rightBedIt = bedList.listIterator(leftBedIt.nextIndex()); rightBedIt .hasNext();) { Bed rightBed = rightBedIt.next(); List<BedDesignation> leftBedDesignationList = bedToBedDesignationList.get(leftBed); if (leftBedDesignationList == null) { leftBedDesignationList = Collections.emptyList(); } List<BedDesignation> rightBedDesignationList = bedToBedDesignationList.get(rightBed); if (rightBedDesignationList == null) { rightBedDesignationList = Collections.emptyList(); } LowestFirstNightBedDesignationIterator lowestIt = new LowestFirstNightBedDesignationIterator( leftBedDesignationList, rightBedDesignationList); // For every pillar part duo while (lowestIt.hasNext()) { BedDesignation pillarPartBedDesignation = lowestIt.next(); // Note: the initialCapacity is probably to high, // which is bad for memory, but the opposite is bad for performance (which is worse) List<Move> moveListByPillarPartDuo = new ArrayList<Move>( leftBedDesignationList.size() + rightBedDesignationList.size()); int lastNightIndex = pillarPartBedDesignation.getAdmissionPart().getLastNight().getIndex(); Bed otherBed; int leftMinimumFirstNightIndex = Integer.MIN_VALUE; int rightMinimumFirstNightIndex = Integer.MIN_VALUE; if (lowestIt.isLastNextWasLeft()) { otherBed = rightBed; leftMinimumFirstNightIndex = lastNightIndex; } else { otherBed = leftBed; rightMinimumFirstNightIndex = lastNightIndex; } moveListByPillarPartDuo.add(new BedChangeMove(pillarPartBedDesignation, otherBed)); // For every BedDesignation in that pillar part duo while (lowestIt.hasNextWithMaximumFirstNightIndexes(leftMinimumFirstNightIndex, rightMinimumFirstNightIndex)) { pillarPartBedDesignation = lowestIt.next(); lastNightIndex = pillarPartBedDesignation.getAdmissionPart().getLastNight().getIndex(); if (lowestIt.isLastNextWasLeft()) { otherBed = rightBed; leftMinimumFirstNightIndex = Math.max(leftMinimumFirstNightIndex, lastNightIndex); } else { otherBed = leftBed; rightMinimumFirstNightIndex = Math.max(rightMinimumFirstNightIndex, lastNightIndex); } moveListByPillarPartDuo.add(new BedChangeMove(pillarPartBedDesignation, otherBed)); } moveList.add(new CompositeMove(moveListByPillarPartDuo)); } } } return moveList; }
From source file:org.drools.planner.examples.traindesign.domain.RailNode.java
public void initializeShortestPathMap(List<RailNode> railNodeList) { shortestPathMap = new HashMap<RailNode, RailNodeShortestPath>(railNodeList.size()); // Dijkstra algorithm List<RailNodeShortestPath> unvisitedShortestPathList = new ArrayList<RailNodeShortestPath>( railNodeList.size());/*from w ww . j av a2 s . c o m*/ RailNodeShortestPath originShortestPath = new RailNodeShortestPath(); originShortestPath.setOrigin(this); originShortestPath.setDestination(this); originShortestPath.setDistance(0); originShortestPath.resetRailPathList(); RailPath originRailPath = new RailPath(new ArrayList<RailArc>(0)); originShortestPath.addRailPath(originRailPath); shortestPathMap.put(this, originShortestPath); unvisitedShortestPathList.add(originShortestPath); while (!unvisitedShortestPathList.isEmpty()) { RailNodeShortestPath campingShortestPath = unvisitedShortestPathList.remove(0); for (RailArc nextRailArc : campingShortestPath.getDestination().getOriginatingRailArcList()) { RailNode nextNode = nextRailArc.getDestination(); int nextDistance = campingShortestPath.getDistance() + nextRailArc.getDistance(); RailNodeShortestPath nextShortestPath = shortestPathMap.get(nextNode); if (nextShortestPath == null) { nextShortestPath = new RailNodeShortestPath(); nextShortestPath.setOrigin(this); nextShortestPath.setDestination(nextNode); nextShortestPath.setDistance(Integer.MAX_VALUE); shortestPathMap.put(nextNode, nextShortestPath); unvisitedShortestPathList.add(nextShortestPath); } if (nextDistance <= nextShortestPath.getDistance()) { if (nextDistance < nextShortestPath.getDistance()) { nextShortestPath.setDistance(nextDistance); nextShortestPath.resetRailPathList(); } for (RailPath campingRailPath : campingShortestPath.getRailPathList()) { List<RailArc> railArcList = new ArrayList<RailArc>(campingRailPath.getRailArcList()); railArcList.add(nextRailArc); RailPath nextRailPath = new RailPath(railArcList); nextShortestPath.addRailPath(nextRailPath); } } } Collections.sort(unvisitedShortestPathList, new Comparator<RailNodeShortestPath>() { public int compare(RailNodeShortestPath a, RailNodeShortestPath b) { return new CompareToBuilder().append(a.getDistance(), b.getDistance()) .append(a.getRailPathList().size(), b.getRailPathList().size()) .append(a.getId(), b.getId()).toComparison(); } }); } }
From source file:org.drools.planner.examples.travelingtournament.domain.solver.Hop.java
public int compareTo(Hop other) { return new CompareToBuilder().append(team, other.team).append(fromTeam, other.fromTeam) .append(toTeam, other.toTeam).toComparison(); }