Examples of RailNodeShortestPath


Examples of org.drools.planner.examples.traindesign.domain.solver.RailNodeShortestPath

                railNodeList.size());
        // Dijkstra algorithm
        List<RailNodeShortestPath> unvisitedShortestPathList = new ArrayList<RailNodeShortestPath>(
                railNodeList.size());

        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) {
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.