Package org.drools.planner.examples.tsp.domain

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


        private TravelingSalesmanTour travelingSalesmanTour;

        private int cityListSize;

        public Solution readSolution() throws IOException {
            travelingSalesmanTour = new TravelingSalesmanTour();
            travelingSalesmanTour.setId(0L);
            readHeaders();
            readCityList();
            readConstantLine("EOF");
            createVisitList();
View Full Code Here


            super(visit.getCity().getSafeName());
            this.visit = visit;
        }

        public void actionPerformed(ActionEvent e) {
            TravelingSalesmanTour travelingSalesmanTour = tspPanel.getTravelingSalesmanTour();
            JComboBox previousAppearanceListField = new JComboBox();
            for (Appearance previousAppearance : travelingSalesmanTour.getVisitList()) {
                previousAppearanceListField.addItem(previousAppearance);
            }
            for (Appearance previousAppearance : travelingSalesmanTour.getDomicileList()) {
                previousAppearanceListField.addItem(previousAppearance);
            }
            previousAppearanceListField.setSelectedItem(visit.getPreviousAppearance());
            int result = JOptionPane.showConfirmDialog(TspListPanel.this.getRootPane(), previousAppearanceListField,
                    "Visit " + visit.getCity().getSafeName() + " after", JOptionPane.OK_CANCEL_OPTION);
View Full Code Here

        private TravelingSalesmanTour travelingSalesmanTour;

        private int cityListSize;

        public Solution readSolution() throws IOException {
            travelingSalesmanTour = new TravelingSalesmanTour();
            travelingSalesmanTour.setId(0L);
            readHeaders();
            readCityList();
            readConstantLine("EOF");
            logger.info("TravelingSalesmanTour with {} cities.",
View Full Code Here

    public TspWorldPanel(TspPanel tspPanel) {
        this.tspPanel = tspPanel;
    }

    public void resetPanel() {
        TravelingSalesmanTour travelingSalesmanTour = tspPanel.getTravelingSalesmanTour();
        double srcMinimumX = Double.MAX_VALUE;
        double srcMaximumX = -Double.MAX_VALUE;
        double srcMinimumY = Double.MAX_VALUE;
        double srcMaximumY = -Double.MAX_VALUE;
        for (City city : travelingSalesmanTour.getCityList()) {
            double x = city.getX();
            if (x < srcMinimumX) {
                srcMinimumX = x;
            }
            if (x > srcMaximumX) {
                srcMaximumX = x;
            }
            double y = city.getY();
            if (y < srcMinimumY) {
                srcMinimumY = y;
            }
            if (y > srcMaximumY) {
                srcMaximumY = y;
            }
        }
        double srcWidth = srcMaximumX - srcMinimumX;
        double srcHeight = srcMaximumY - srcMinimumY;

        Dimension size = getSize();
        double width = size.getWidth();
        double height = size.getHeight();
        int canvasWidth = (int) Math.ceil(width) + 1;
        int canvasHeight = (int) Math.ceil(height) + 1;
        canvas = new BufferedImage(canvasWidth, canvasHeight, BufferedImage.TYPE_INT_RGB);
        Graphics g = canvas.getGraphics();
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, canvasWidth, canvasHeight);
        g.setColor(Color.RED);
        for (City city : travelingSalesmanTour.getCityList()) {
            int x = translateCoordinate(srcMinimumX, srcWidth, width, city.getX());
            int y = translateCoordinate(srcMinimumY, srcHeight, height, city.getY());
            g.fillRect(x - 1, y - 1, 3, 3);
        }
        g.setColor(Color.BLACK);
        if (travelingSalesmanTour.isInitialized()) {
            for (CityAssignment cityAssignment : travelingSalesmanTour.getCityAssignmentList()) {
                City city = cityAssignment.getCity();
                int x1 = translateCoordinate(srcMinimumX, srcWidth, width, city.getX());
                int y1 = translateCoordinate(srcMinimumY, srcHeight, height, city.getY());
                City nextCity = cityAssignment.getNextCityAssignment().getCity();
                int x2 = translateCoordinate(srcMinimumX, srcWidth, width, nextCity.getX());
View Full Code Here

public class TspStartingSolutionInitializer extends AbstractStartingSolutionInitializer {

    @Override
    public boolean isSolutionInitialized(AbstractSolverScope abstractSolverScope) {
        TravelingSalesmanTour travelingSalesmanTour = (TravelingSalesmanTour) abstractSolverScope.getWorkingSolution();
        return travelingSalesmanTour.isInitialized();
    }
View Full Code Here

import org.drools.planner.examples.tsp.solver.move.SubTourChangeMove;

public class SubTourChangeMoveFactory extends CachedMoveFactory {

    public List<Move> createCachedMoveList(Solution solution) {
        TravelingSalesmanTour travelingSalesmanTour = (TravelingSalesmanTour) solution;
        List<Move> moveList = new ArrayList<Move>();
        List<CityAssignment> cityAssignmentList = travelingSalesmanTour.getCityAssignmentList();
        for (CityAssignment startCityAssignment : cityAssignmentList) {
            for (CityAssignment endCityAssignment : cityAssignmentList) {
                for (CityAssignment toAfterCityAssignment : cityAssignmentList) {
                    moveList.add(new SubTourChangeMove(startCityAssignment, endCityAssignment, toAfterCityAssignment));
                }
View Full Code Here

        TravelingSalesmanTour travelingSalesmanTour = (TravelingSalesmanTour) abstractSolverScope.getWorkingSolution();
        return travelingSalesmanTour.isInitialized();
    }

    public void initializeSolution(AbstractSolverScope abstractSolverScope) {
        TravelingSalesmanTour travelingSalesmanTour = (TravelingSalesmanTour) abstractSolverScope.getWorkingSolution();
        initializeCityAssignmentList(abstractSolverScope, travelingSalesmanTour);
    }
View Full Code Here

        setLayout(new GridLayout(0, 1));
    }

    public void resetPanel() {
        removeAll();
        TravelingSalesmanTour travelingSalesmanTour = tspPanel.getTravelingSalesmanTour();
        JLabel headerLabel = new JLabel("Tour of " + travelingSalesmanTour.getName());
        headerLabel.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLineBorder(Color.DARK_GRAY),
                BorderFactory.createEmptyBorder(2, 2, 2, 2)));
        headerLabel.setBackground(HEADER_COLOR);
        headerLabel.setOpaque(true);
        add(headerLabel);
        if (travelingSalesmanTour.isInitialized()) {
            for (CityAssignment cityAssignment : travelingSalesmanTour.getCityAssignmentList()) {
                JPanel cityAssignmentPanel = new JPanel(new GridLayout(1, 2));
                JButton button = new JButton(new CityAssignmentAction(cityAssignment));
                cityAssignmentPanel.add(button);
                JLabel distanceLabel = new JLabel("Distance to next: "
                        + cityAssignment.getDistanceToNextCityAssignment());
View Full Code Here

    public TravelingSalesmanTour getTravelingSalesmanTour() {
        return (TravelingSalesmanTour) solutionBusiness.getSolution();
    }

    public void resetPanel(Solution solution) {
        TravelingSalesmanTour travelingSalesmanTour = (TravelingSalesmanTour) solution;
        tspWorldPanel.resetPanel(travelingSalesmanTour);
        tspListPanel.resetPanel(travelingSalesmanTour);
        resetNextCityId();
    }
View Full Code Here

        nextCityId = highestCityId + 1L;
    }

    @Override
    public void updatePanel(Solution solution) {
        TravelingSalesmanTour travelingSalesmanTour = (TravelingSalesmanTour) solution;
        tspWorldPanel.updatePanel(travelingSalesmanTour);
        tspListPanel.updatePanel(travelingSalesmanTour);
    }
View Full Code Here

TOP

Related Classes of org.drools.planner.examples.tsp.domain.TravelingSalesmanTour

Copyright © 2018 www.massapicom. 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.