我有一个列表,想要将它连接到java中的另一个列表。第一个列表计算最短路径,另一个列表具有汽车的航点。当我从最短的路径得到答案时,我想将其连接到航路点
package Main;
import PathfindingEasy.DijkstraAlgorithm;
import PathfindingEasy.Edge;
import PathfindingEasy.Graph;
import PathfindingEasy.Vertex;
import com.jme3.asset.AssetManager;
import com.jme3.scene.Node;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/**
*
* @author NathanStowers
*/
public class PathFinder {
Node rootNode;
AssetManager assetManager;
private List<Vertex> nodes;
private List<Edge> edges;
PathFinder(Node rootNode, AssetManager assetManager) {
this.rootNode = rootNode;
this.assetManager = assetManager;
}
public void pathExcute() {
nodes = new ArrayList<>();
edges = new ArrayList<>();
for (int i = 0; i < 317; i++) {
Vertex location = new Vertex(i, "Node_" + i);
nodes.add(location);
}
ListHandler lh = new ListHandler(rootNode, assetManager);
//dummy data
for (int i = 0; i < 78; i++){
addLane("lLane1_"+i, i, i + 1, 10);
}
addLane("lLane1_78", 0, 78, 780);
for (int i = 79; i < 157; i++){
addLane("rLane1_"+i, i, i + 1, 10);
}
addLane("rLane_157", 79, 157, 780);
addLane("connectlL1_rL1_1", 78, 79, 300);
addLane("connectlL1_rL1_2", 157, 0, 300);
for (int i = 78; i > 0; i--) {
addLane("lLane2_"+i, i, i - 1, 10);
}
addLane("lLane2_78", 78, 0, 780);
for (int i = 157; i > 79; i--) {
addLane("rLane2_"+i, i, i - 1, 10);
}
addLane("rLane_157", 157, 79, 780);
addLane("conectlL2_rL2_1", 79, 78, 300);
addLane("connectlL2_rL2_2", 0, 157, 300);
int k = 162;
for (int i = 43; i < 79; i += 5) {
addLane("bargeLane_" + i, i, k, 10);
k += 3;
}
int j = 40;
for (int i = 160; i < 182; i += 3) {
addLane("bargeLane_" + i, i, j, 10);
j += 5;
}
int h = 162;
for(int i = 0; i < 16; i+=2){
addLane("underBargeCrane_" +i, h, h-1, 10);
addLane("underBargeCrane_" +i+1, h-1, h-2, 10);
h+=3;
}
for (int i = 190; i < 211; i++) {
addLane("underTrainCrane_" + i, i, i + 1, 10);
}
addLane("connectToTrain_1", 79, 190, 10);
addLane("conectToTrain_2", 211, 97, 10);
for (int i = 220; i < 226; i++) {
addLane("topLaneL_" + i, i, i + 1, 33);
}
for (int i = 230; i < 236; i++) {
addLane("topLaneR_" + i, i, i + 1, 33);
}
addLane("connectTopL_1", 78, 220, 10);
addLane("connectTopL_2", 226, 79, 10);
addLane("connectTopR_1", 79, 230, 10);
addLane("connectTopR_2", 236, 78, 10);
int z = 243;
for (int i = 230; i < 237; i++) {
addLane("connectToSeaShip_" + i, i, z, 33);
z += 3;
}
int x = 245;
for (int i = 220; i < 227; i++) {
addLane("connectToSeaShip_" + i, x, i, 33);
x += 3;
}
int q = 240;
for(int i = 0; i < 16; i+=2){
addLane("underBargeCrane_" +i, q, q+1, 10);
addLane("underBargeCrane_" +i+1, q+1, q+2, 10);
q+=3;
}
addLane("connectTopShip_1", 78, 240, 10);
addLane("connectTopShip_2", 263, 79, 10);
// Lets check from location Loc_a to Loc_b
Graph graph = new Graph(nodes, edges);
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(graph);
dijkstra.execute(nodes.get(0));
LinkedList<Vertex> path = dijkstra.getPath(nodes.get(256));
for (Vertex vertex : path) {
System.out.println(vertex);
}
}
private void addLane(String laneId, int sourceLocNo, int destLocNo,
int duration) {
Edge lane = new Edge(laneId, nodes.get(sourceLocNo), nodes.get(destLocNo), duration);
edges.add(lane);
}
}
这是具有最短路径的类
private void setWayPoints(){
//Loop for the dockingCrane waypoints
for (int i = 0; i < 3; i++)
{
if(i==0)
{
for(int j = 0; j < dCraneArray.length; j++)
{
dCraneArray[j].add(new Waypoint(rootNode, assetManager));
dCraneArray[j].get(i).setPosition(-15f+(j*200f), 0f, -685f);
}
}
else if (i==1)
{
for(int j = 0; j < dCraneArray.length; j++)
{
dCraneArray[j].add(new Waypoint(rootNode, assetManager));
dCraneArray[j].get(i).setPosition(50f+(j*200f), 0f, -685f);
}
}
else if (i==2)
{
for(int j = 0; j < dCraneArray.length-1; j++)
{
dCraneArray[j].add(new Waypoint(rootNode, assetManager));
dCraneArray[j].get(i).setPosition(105f+(j*200f), 0f, -685f);
}
dCrane8.add(new Waypoint(rootNode, assetManager));
dCrane8.get(i).setPosition(1529f, 0f, -685f);
}
}
//Loop for the ShipCrane waypoints
for (int i = 0; i < 3; i++)
{
//waypoint for entrance
if(i==0){
for(int j = 0; j < sCraneArray.length; j++)
{
if(j== sCraneArray.length-1){
sCraneArray[j].add(new Waypoint(rootNode, assetManager));
sCraneArray[j].get(i).setPosition(1595f, 0f, -368f+(j*144));
}
else{
sCraneArray[j].add(new Waypoint(rootNode, assetManager));
sCraneArray[j].get(i).setPosition(1595f, 0f, -461f+(j*144));
}
}
}
//waypoint for center
if(i==1){
for(int j = 0; j < sCraneArray.length; j++)
{
sCraneArray[j].add(new Waypoint(rootNode, assetManager));
sCraneArray[j].get(i).setPosition(1595f, 0f, -500f+(j*139f));
}
}
//waypoint for exit
if(i==2){
for(int j = 0; j < sCraneArray.length; j++)
{
if(j==sCraneArray.length-1){
sCraneArray[j].add(new Waypoint(rootNode, assetManager));
sCraneArray[j].get(i).setPosition(1595f, 0f, -620f);
}
else{
sCraneArray[j].add(new Waypoint(rootNode, assetManager));
sCraneArray[j].get(i).setPosition(1595f, 0f, -440f+(j*144f));
}
}
}
这是航点类