⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ant.java

📁 P2P模拟器P2Psim的程序源码
💻 JAVA
字号:

package graph;

import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.GraphConstants;

import org.jgraph.graph.DefaultPort;

//import java.util.Iterator;

public class Ant
{

	public Ant(DefaultGraphCell origin, String searchFor, DefaultGraphCell nextNode)
	{
		this.origin = origin;
		this.searchFor = searchFor;
		this.previousNode = origin;
		this.nextNode = nextNode;
		this.progress = 0;
		this.status = MOVING;
	}

	public void run(DefaultGraphCell dgc)
	{
		Properties properties = (Properties)GraphConstants.getValue(dgc.getAttributes());
		
		//System.out.println("Ant searching for " + searchFor + " - next destination: " + nextNode + " - progress: " + progress);
		//progress++;
		
		// Ant bevindt zich op een edge
		if (dgc instanceof DefaultEdge)
		{
			if (status == MOVING)
			{
				if (progress == 3)
				{
					// We zijn aan de volgende knoop
					System.out.println("Geariveerd in " + nextNode);
					
					//Spring van de edge
					properties.removeInformation("Ants", this);
					
					//Kruip in de volgende vertex
					Properties nextNodeProperties = (Properties)GraphConstants.getValue(nextNode.getAttributes());
					nextNodeProperties.addInformation("Ants", this);
					
					status = SEARCHING;
				}
				else
				{
					progress++;
					System.out.println("Progress = " + progress);
				}
			}
		}
		// Ant bevindt zich in een vertex
		else
		{
			if (status == MOVING)
			{
				properties.removeInformation("Ants", this);
				DefaultEdge newEdge = GraphEventManager.getReference().eventGetConnectingEdge(previousNode, nextNode);
				//System.out.println(newEdge);
				
				System.out.print("van " + ((DefaultGraphCell)((DefaultPort)newEdge.getSource()).getParent()) + " naar  ");
									System.out.println(((DefaultGraphCell)((DefaultPort)newEdge.getTarget()).getParent()));
				
				Properties edgeProperties = (Properties)GraphConstants.getValue(newEdge.getAttributes());
				edgeProperties.addInformation("Ants", this);
			}
		}	
	}
	
	public DefaultGraphCell getDestination()
	{
		return nextNode;
	}
	
	public DefaultGraphCell getSource()
	{
		return previousNode;
	}
	
	public int getProgress()
	{
		return progress;
	}


	private DefaultGraphCell origin;
	private String searchFor;
	private DefaultGraphCell previousNode;
	private DefaultGraphCell nextNode;
	private int progress;

	private int status;
	private static final int MOVING = 1;
	private static final int SEARCHING = 2;
	private static final int EXPLORING = 3;
	private static final int RETURNING = 4;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -