Package org.optaplanner.examples.tsp.domain.location

Examples of org.optaplanner.examples.tsp.domain.location.Location


    public SolverAndPersistenceFrame getWorkflowFrame() {
        return solverAndPersistenceFrame;
    }

    public void insertLocationAndVisit(double longitude, double latitude) {
        final Location newLocation;
        switch (getTravelingSalesmanTour().getDistanceType()) {
            case AIR_DISTANCE:
                newLocation = new AirLocation();
                break;
            case ROAD_DISTANCE:
                logger.warn("Adding locations for a road distance dataset is not supported.");
                return;
            default:
                throw new IllegalStateException("The distanceType (" + getTravelingSalesmanTour().getDistanceType()
                        + ") is not implemented.");
        }
        newLocation.setId(nextLocationId);
        nextLocationId++;
        newLocation.setLongitude(longitude);
        newLocation.setLatitude(latitude);
        logger.info("Scheduling insertion of newLocation ({}).", newLocation);
        doProblemFactChange(new ProblemFactChange() {
            public void doChange(ScoreDirector scoreDirector) {
                TravelingSalesmanTour solution = (TravelingSalesmanTour) scoreDirector.getWorkingSolution();
                scoreDirector.beforeProblemFactAdded(newLocation);
                solution.getLocationList().add(newLocation);
                scoreDirector.afterProblemFactAdded(newLocation);
                Visit newVisit = new Visit();
                newVisit.setId(newLocation.getId());
                newVisit.setLocation(newLocation);
                scoreDirector.beforeEntityAdded(newVisit);
                solution.getVisitList().add(newVisit);
                scoreDirector.afterEntityAdded(newVisit);
            }
View Full Code Here


            DistanceType distanceType = travelingSalesmanTour.getDistanceType();
            List<Location> locationList = new ArrayList<Location>(locationListSize);
            for (int i = 0; i < locationListSize; i++) {
                String line = bufferedReader.readLine();
                String[] lineTokens = splitBySpace(line, 3, 4);
                Location location;
                switch (distanceType) {
                    case AIR_DISTANCE:
                        location = new AirLocation();
                        break;
                    case ROAD_DISTANCE:
                        location = new RoadLocation();
                        break;
                    default:
                        throw new IllegalStateException("The distanceType (" + distanceType
                                + ") is not implemented.");

                }
                location.setId(Long.parseLong(lineTokens[0]));
                location.setLatitude(Double.parseDouble(lineTokens[1]));
                location.setLongitude(Double.parseDouble(lineTokens[2]));
                if (lineTokens.length >= 4) {
                    location.setName(lineTokens[3]);
                }
                locationList.add(location);
            }
            travelingSalesmanTour.setLocationList(locationList);
            if (distanceType == DistanceType.ROAD_DISTANCE) {
                readConstantLine("EDGE_WEIGHT_SECTION");
                for (int i = 0; i < locationListSize; i++) {
                    RoadLocation location = (RoadLocation) locationList.get(i);
                    Map<RoadLocation, Double> travelDistanceMap = new LinkedHashMap<RoadLocation, Double>(locationListSize);
                    String line = bufferedReader.readLine();
                    String[] lineTokens = splitBySpacesOrTabs(line.trim(), locationListSize);
                    for (int j = 0; j < locationListSize; j++) {
                        double travelDistance = Double.parseDouble(lineTokens[j]);
                        if (i == j) {
                            if (travelDistance != 0.0) {
                                throw new IllegalStateException("The travelDistance (" + travelDistance
                                        + ") should be zero.");
                            }
                        } else {
                            RoadLocation otherLocation = (RoadLocation) locationList.get(j);
                            travelDistanceMap.put(otherLocation, travelDistance);
                        }
                    }
                    location.setTravelDistanceMap(travelDistanceMap);
                }
            }
        }
View Full Code Here

            List<Location> locationList = new ArrayList<Location>(locationListSize);
            long id = 0;
            for (int i = 0; i < locationListSize; i++) {
                String line = bufferedReader.readLine();
                String[] lineTokens = splitBySpace(line, 2);
                Location location = new AirLocation();
                location.setId(id);
                id++;
                location.setLatitude(Double.parseDouble(lineTokens[0]));
                location.setLongitude(Double.parseDouble(lineTokens[1]));
                locationList.add(location);
            }
            travelingSalesmanTour.setLocationList(locationList);
            createVisitList();
        }
View Full Code Here

        }
        g.setFont(g.getFont().deriveFont((float) LOCATION_NAME_TEXT_SIZE));
        g.setColor(TangoColorFactory.PLUM_2);
        List<Visit> visitList = travelingSalesmanTour.getVisitList();
        for (Visit visit : visitList) {
            Location location = visit.getLocation();
            int x = translator.translateLongitudeToX(location.getLongitude());
            int y = translator.translateLatitudeToY(location.getLatitude());
            g.fillRect(x - 1, y - 1, 3, 3);
            if (location.getName() != null && visitList.size() <= 500) {
                g.drawString(location.getName(), x + 3, y - 3);
            }
        }
        g.setColor(TangoColorFactory.ALUMINIUM_4);
        Domicile domicile = travelingSalesmanTour.getDomicile();
        Location domicileLocation = domicile.getLocation();
        int domicileX = translator.translateLongitudeToX(domicileLocation.getLongitude());
        int domicileY = translator.translateLatitudeToY(domicileLocation.getLatitude());
        g.fillRect(domicileX - 2, domicileY - 2, 5, 5);
        if (domicileLocation.getName() != null && visitList.size() <= 500) {
            g.drawString(domicileLocation.getName(), domicileX + 3, domicileY - 3);
        }
        Set<Visit> needsBackToDomicileLineSet = new HashSet<Visit>(visitList);
        for (Visit trailingVisit : visitList) {
            if (trailingVisit.getPreviousStandstill() instanceof Visit) {
                needsBackToDomicileLineSet.remove(trailingVisit.getPreviousStandstill());
            }
        }
        g.setColor(TangoColorFactory.CHOCOLATE_1);
        for (Visit visit : visitList) {
            if (visit.getPreviousStandstill() != null) {
                Location previousLocation = visit.getPreviousStandstill().getLocation();
                Location location = visit.getLocation();
                translator.drawRoute(g, previousLocation.getLongitude(), previousLocation.getLatitude(),
                        location.getLongitude(), location.getLatitude(),
                        location instanceof AirLocation);
                // Back to domicile line
                if (needsBackToDomicileLineSet.contains(visit)) {
                    translator.drawRoute(g, location.getLongitude(), location.getLatitude(),
                            domicileLocation.getLongitude(), domicileLocation.getLatitude(),
                            location instanceof AirLocation);
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.optaplanner.examples.tsp.domain.location.Location

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.