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

📄 call.cs

📁 ACO.zip是一个蚁群优化算法
💻 CS
字号:
using System;
using System.Collections;

namespace ACO
{
	/// <summary>
	/// A call represents an call placed on the network
	/// </summary>
	public class Call
	{
		#region properties

		// the maximum length of the call
		public int Duration;
		// unique identifier
		public int CallID;
		// the starting node of the call
		public int SourceNodeID;
		// the final desitination of the call
		public int DestinationNodeID;
		// the current node the call is on
		public int CurrentNodeID;
		// an array of all visited node ids
		public ArrayList VisitedNodes= new ArrayList();
		// an array of final visted arrays after xxxx
		public  ArrayList FinalVisitedNodes= new ArrayList();
		// has the call finished
		public bool Finished=false;
		// has the call failed
		public bool HasFailed=false;
		// which direction is the ant agent moving in
		public eAntDirection AntDirection;
		// the new value of the node
		public double NewValue=-1;
		// the final count for visited nodes
		public int finalVisitedNodeCount=0;
		// total wait time for the call
		public int waitTime=0;
		// if the call was successful
		public bool Successful=false;


		// create a new call with a source and destination node
		public Call(int src, int dest)
		{
			this.CallID = Global.CallID;
			this.SourceNodeID = src;
			this.DestinationNodeID = dest;
			this.CurrentNodeID = src;
			this.VisitedNodes.Add(this.SourceNodeID);
			this.Duration=Global.CallDuration;
		}

		#endregion

		// terminates the call and releases all network resources
		public void TerminateCall()
		{
			Node n;

			// loop through all the nodes
			for(int i=0;i<Global.Nodes.Length;i++)
			{
				// get the ith node
				n = Global.Nodes[i];

				// loop through all the calls on this node
				for(int j=0;j<n.CallIDS.Count;j++)
				{
					// if the Call ID is present on the node then release
					if(((int)n.CallIDS[j])==this.CallID)
					{
						// remove the call
						n.CallIDS.RemoveAt(j);
						// reset the outer loop indexer
						j=0;
					}
				}
			}
		}

		// this method is called before the ant agent moves in reverse.
		// any loops in the path will be removed to optimise routing
		public void LoopRemoval()
		{
			int id1; 
			int id2;

			// loop through all the nodes to find multiple occurances
			// of the same path.
			for(int i=0;i<VisitedNodes.Count;i++)
			{
				id1 = (int)VisitedNodes[i];

				for(int j=i+1;j<VisitedNodes.Count-1;j++)
				{
					id2 = (int)VisitedNodes[j];

					// if a loop has been found
					if(id1==id2)
					{
						// create a tempory arraylist
						ArrayList tArray = new ArrayList();

						for(int k=0;k<VisitedNodes.Count-1;k++)
						{
							//if(k>-1 && k)
							tArray.Add(VisitedNodes[k]);
						}

						VisitedNodes = tArray;

						//reset the outer loop indexer
						i=0;
					}
				}
			}
		}

		// Gets the next Node to travel to
		public int ConnectNextNode()
		{
			Node n = Global.Nodes[this.CurrentNodeID];

			// loop to determine if a direct connection is possible
			for(int i=0;i<n.Connections.Length;i++)
			{
				// if the destination node is directly connected
				if(n.Connections[i]==this.DestinationNodeID)
					return n.Connections[i];
			}

			// otherwise use the Phermomone table
			for(int i=0;i<n.PheromoneTable.Length;i++)
			{
				// find the corresponding pheromone table
				if(this.DestinationNodeID==n.PheromoneTable[i].NodeID)
				{
					PheromoneTable p = n.PheromoneTable[i];
					// return its probable path
					return p.ProbablePath(VisitedNodes);
				}
			}

			// if all nodes are busy retun -1 and inform to wait
			return -1;
		}
	}
}

⌨️ 快捷键说明

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