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

📄 global.cs

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

namespace ACO
{
	// The direction an ant is travelling in
	public enum eAntDirection{ForwardAnt, BackwardAnt};

	/// Holds all global static variables and methods for the application
	public class Global
	{
		// the maximum call length before failing
		public static int CallDuration = 40;
		// Number of nodes of the network
		public const int NumberOfNodes = 30;
		// the maximum number of calls a node can carry 
		public static int NodeCapacity = 10;
		// the total number of completed calls made
		public static int TotalCallsMade=0;
		// the total number of calls to simulate
		public static int TotalCalls=0;
		// the maximum number of concurrent calls
		public static int MaxConcurrentCalls=0;
		// The nodes in the network
		public static Node[] Nodes = new Node[NumberOfNodes];
		// The calls on the network
		public static ArrayList Calls = new ArrayList();
		// the id of the last call generated++
		private static int callID = 0;
		// the last seed used for random node src and dest creation
		public static int LastSeed = 100;
		// the scale of the visual network map
		public static double Scale = 1.4;
		// an array of all the simulations run
		public static ArrayList Simulations = new ArrayList();
		// the new seed for random generation
		private static int seed=100;
		 
		// get a new calID
		public static int CallID
		{
			get{return ++callID;}
		}


		// get a new seed for the random function
		public static int Seed
		{
			get
			{
				// this is to make the same seed isnt chosen in the same space of time
				if(seed>1999999999)
					seed=DateTime.Now.Millisecond;

				return seed +=17;
			}
		}


		// renders all the pheromone tables to disk as an HTML file
		public static void WriteTablesToDisk()
		{
			PheromoneTable p;
			Node n;

			// render the header
			string html="<body><font face=arial><table width=100% border=1 cellspacing=0 style='font-size:11px'>";

			// loop through all the nodes
			for(int i=0;i<Global.Nodes.Length;i++)
			{
				// render the header for the ith node
				html+="<tr><td colspan=5 bgcolor=bbbbbb><strong>Phermomone Tables for Node "+i+"<strong></td></tr>";
				n = Global.Nodes[i];

				// loop through all the pheromone tables
				for(int j=0;j<n.PheromoneTable.Length;j++)
				{
					p = n.PheromoneTable[j];

					// add the row data
					html+="<tr bgcolor=dddddd><td width=10%>&nbsp;</td><td><strong>Destination Node</strong></td><td><strong>Next Possible Node</strong></td><td><strong>Proablity of Node being quickest</strong></td></tr>";
					
					// render all the table entry possibility values
					for(int k=0;k<p.tableEntry.Length;k++)
					{
						html+="<tr><td width=10%>&nbsp;</td><td>Node "+p.NodeID+"</td><td>Node "+p.tableEntry[k].NodeID+"</td><td>"+p.tableEntry[k].Probablilty+"%</td></tr>";
					}
				}		
			}

			// close the table
			html+="</font><body><table width=100%>";

			// write the stream to an HTML on disk
			TextWriter t = new StreamWriter(@"c:\ANTNET.htm");
			t.Write(html);

			// flush the writeer objec and close the file
			t.Flush();
			t.Close();
		}


		// Returns a call by its CallID
		public static Call GetCall(int CallID)
		{
			// loop through all calls
			for(int i=0;i<Global.Calls.Count;i++)
			{
				// if the callIDs match then return the call
				if(((Call)Global.Calls[i]).CallID==CallID)
					return (Call)Global.Calls[i];
			}

			//otherwise the call wasnt found
			return null;
		}

		// Terminate all calls on the network
		public static void TerminateAllCalls()
		{
			for(int i=0;i<Global.Nodes.Length;i++)
				Global.Nodes[i].CallIDS.Clear();			
		}


		private Global(){}
	}
}

⌨️ 快捷键说明

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