Examples of CityAssignment


Examples of org.drools.planner.examples.tsp.domain.CityAssignment

        this.endCityAssignment = endCityAssignment;
        this.toAfterCityAssignment = toAfterCityAssignment;
    }

    public boolean isMoveDoable(WorkingMemory workingMemory) {
        CityAssignment nextCityAssignment = startCityAssignment;
        if (ObjectUtils.equals(startCityAssignment, toAfterCityAssignment.getNextCityAssignment())) {
            return false;
        }
        while (!ObjectUtils.equals(nextCityAssignment, endCityAssignment)) {
            if (ObjectUtils.equals(nextCityAssignment, toAfterCityAssignment)) {
                return false;
            }
            nextCityAssignment = nextCityAssignment.getNextCityAssignment();
        }
        if (ObjectUtils.equals(endCityAssignment, toAfterCityAssignment)) {
            return false;
        }
        return true;
View Full Code Here

Examples of org.drools.planner.examples.tsp.domain.CityAssignment

        return new SubTourChangeMove(startCityAssignment, endCityAssignment,
                startCityAssignment.getPreviousCityAssignment());
    }

    public void doMove(WorkingMemory workingMemory) {
        CityAssignment newPreviousCityAssignment = toAfterCityAssignment;
        CityAssignment newNextCityAssignment = newPreviousCityAssignment.getNextCityAssignment();
        CityAssignment originalPreviousCityAssignment = startCityAssignment.getPreviousCityAssignment();
        CityAssignment originalNextCityAssignment = endCityAssignment.getNextCityAssignment();
        TspMoveHelper.moveCityAssignmentAfterCityAssignment(workingMemory, newPreviousCityAssignment, startCityAssignment);
        TspMoveHelper.moveCityAssignmentAfterCityAssignment(workingMemory, endCityAssignment, newNextCityAssignment);
        TspMoveHelper.moveCityAssignmentAfterCityAssignment(workingMemory, originalPreviousCityAssignment, originalNextCityAssignment);
    }
View Full Code Here

Examples of org.drools.planner.examples.tsp.domain.CityAssignment

                cityAssignment.setNextCityAssignment(cityAssignment);
                cityAssignment.setPreviousCityAssignment(cityAssignment);
                cityAssignmentHandle = workingMemory.insert(cityAssignment);
            } else {
                Score bestScore = DefaultSimpleDoubleScore.valueOf(-Double.MAX_VALUE);
                CityAssignment bestAfterCityAssignment = null;
                FactHandle bestAfterCityAssignmentFactHandle = null;
                CityAssignment bestBeforeCityAssignment = null;
                FactHandle bestBeforeCityAssignmentFactHandle = null;
                for (CityAssignment afterCityAssignment : assignedCityAssignmentList) {
                    CityAssignment beforeCityAssignment = afterCityAssignment.getNextCityAssignment();
                    FactHandle afterCityAssignmentFactHandle = workingMemory.getFactHandle(afterCityAssignment);
                    FactHandle beforeCityAssignmentFactHandle = workingMemory.getFactHandle(beforeCityAssignment);
                    // Do changes
                    afterCityAssignment.setNextCityAssignment(cityAssignment);
                    cityAssignment.setPreviousCityAssignment(afterCityAssignment);
                    cityAssignment.setNextCityAssignment(beforeCityAssignment);
                    beforeCityAssignment.setPreviousCityAssignment(cityAssignment);
                    if (cityAssignmentHandle == null) {
                        cityAssignmentHandle = workingMemory.insert(cityAssignment);
                    } else {
                        workingMemory.update(cityAssignmentHandle, cityAssignment);
                    }
                    workingMemory.update(afterCityAssignmentFactHandle, afterCityAssignment);
                    workingMemory.update(beforeCityAssignmentFactHandle, beforeCityAssignment);
                    // Calculate score
                    Score score = abstractSolverScope.calculateScoreFromWorkingMemory();
                    if (score.compareTo(bestScore) > 0) {
                        bestScore = score;
                        bestAfterCityAssignment = afterCityAssignment;
                        bestAfterCityAssignmentFactHandle = afterCityAssignmentFactHandle;
                        bestBeforeCityAssignment = beforeCityAssignment;
                        bestBeforeCityAssignmentFactHandle = beforeCityAssignmentFactHandle;
                    }
                    // Undo changes
                    afterCityAssignment.setNextCityAssignment(beforeCityAssignment);
                    beforeCityAssignment.setPreviousCityAssignment(afterCityAssignment);
                    workingMemory.update(afterCityAssignmentFactHandle, afterCityAssignment);
                    workingMemory.update(beforeCityAssignmentFactHandle, beforeCityAssignment);
                }
                if (bestAfterCityAssignment == null) {
                    throw new IllegalStateException("The bestAfterCityAssignment (" + bestAfterCityAssignment
View Full Code Here

Examples of org.drools.planner.examples.tsp.domain.CityAssignment

        List<City> cityList = travelingSalesmanTour.getCityList();
        // TODO weight: create by city on distance from the center ascending
        List<CityAssignment> cityAssignmentList = new ArrayList<CityAssignment>(cityList.size());
        int cityAssignmentId = 0;
        for (City city : cityList) {
            CityAssignment cityAssignment = new CityAssignment();
            cityAssignment.setId((long) cityAssignmentId);
            cityAssignment.setCity(city);
            cityAssignmentList.add(cityAssignment);
            cityAssignmentId++;
        }
        return cityAssignmentList;
    }
View Full Code Here

Examples of org.drools.planner.examples.tsp.domain.CityAssignment

            afterCityAssignmentListField.setSelectedItem(cityAssignment.getNextCityAssignment());
            listFieldsPanel.add(afterCityAssignmentListField);
            int result = JOptionPane.showConfirmDialog(TspListPanel.this.getRootPane(), listFieldsPanel,
                    "Select to move after city", JOptionPane.OK_CANCEL_OPTION);
            if (result == JOptionPane.OK_OPTION) {
                CityAssignment toAfterCityAssignment = (CityAssignment) afterCityAssignmentListField.getSelectedItem();
                tspPanel.doMove(new SubTourChangeMove(cityAssignment, cityAssignment, toAfterCityAssignment));
                tspPanel.getWorkflowFrame().updateScreen();
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.