private InputParameters ip;		// Reference to input parameter object

		/// <summary>
		/// Class constructor
		/// </summary>
		/// <param name="ip">InputParameters instance</param>
		public FixedPeriodVariableSize(InputParameters _ip) : base(_ip)
		{
			double []temp1, temp2;
			int []temp3;
			int tempVar;
			int idx;

			this.ip = _ip;

			#region Code to normalize input arrival rates
			ip.getArrivalRateVRoads(out temp1);
			ip.getArrivalRateHRoads(out temp2);

			this.normalizeInput(temp1, temp2);
			#endregion

			#region Code to compute hyperperiod
			temp3 = new Int32[arrivalHRoads.Length + arrivalVRoads.Length];

			idx = 0;

			for(int i = 0; i < arrivalHRoads.Length; i++)
				temp3[idx++] = arrivalHRoads[i];
			for(int i = 0; i < arrivalVRoads.Length; i++)
				temp3[idx++] = arrivalVRoads[i];

			H = ComputeLCM.LCM(temp3);
			#endregion

			Console.WriteLine("Hyperperiod = " + H);

			/**
			 * We compute execution time along each intersection as the fraction of the traffic
			 * flowing through that intersection in the direction under consideration. Then, for
			 * each intersection along the road, we find the minimum value of execution time along
			 * that road in the specified direction. That value is the execution time (platoon length)
			 * along that road.
			 */

			#region Code to compute execution time on NS roads

			eVRoads = new int[arrivalVRoads.Length];

			for(int i = 0; i < arrivalVRoads.Length; i++)
			{
				tempVar = Convert.ToInt32(Math.Floor((1.0 * arrivalVRoads[i] / (arrivalVRoads[i] + arrivalHRoads[0]) * H)));
				eVRoads[i] = tempVar;
				
				for(int j = 1; j < arrivalHRoads.Length; j++)
				{
					tempVar = Convert.ToInt32(Math.Floor((1.0 * arrivalVRoads[i] / (arrivalVRoads[i] + arrivalHRoads[j]) * H)));

					if(tempVar < eVRoads[i])
						eVRoads[i] = tempVar;
				}
			}
			#endregion
//#if DDEBUG
			Console.WriteLine("Printing list of E along NS roads");

			for(int i = 0; i < eVRoads.Length; i++)
			{
				Console.WriteLine(eVRoads[i]);
			}
//#endif
			#region Code to compute execution time on EW roads

			eHRoads = new int[arrivalHRoads.Length];

			for(int i = 0; i < arrivalHRoads.Length; i++)
			{
				eHRoads[i] = Convert.ToInt32(Math.Floor((1.0 * arrivalHRoads[i] / (arrivalHRoads[i] + arrivalVRoads[0]) * H)));

				for(int j = 1; j < arrivalVRoads.Length; j++)
				{
					tempVar = Convert.ToInt32(Math.Floor((1.0 * arrivalHRoads[i] / (arrivalHRoads[i] + arrivalVRoads[j]) * H)));

						if(tempVar < eHRoads[i])
							eHRoads[i] = tempVar;
				}
			}
			#endregion
//#if DDEBUG
			Console.WriteLine("Printing list of E along EW roads");

			for(int i = 0; i < eHRoads.Length; i++)
			{
				Console.WriteLine(eHRoads[i]);
			}
//#endif

			/**
			 * From the execution time at each intersection, we can determine the platoon lengths and hence the 
			 * number of vehicles in each platoon.
			 */
			pLenVRoads = new int[eVRoads.Length];
			pLenHRoads = new int[eHRoads.Length];
			platoonSizeVRoads = new int[eVRoads.Length];
			platoonSizeHRoads = new int[eHRoads.Length];

			for(int i = 0; i < eVRoads.Length; i++)
			{
				/**
				 * Compute platoon length as
				 * SpeedLimit * E - W
				 */
				pLenVRoads[i] = ip.speedLimit * eVRoads[i] - ip.lengthW;

				/**
				 * Compute how many vehicles can fit in this platoon
				 */
				tempVar = pLenVRoads[i] / (ip.intraPlatoonDist + ip.vehicleLen);
				platoonSizeVRoads[i] = tempVar;

				/**
				 * Check if one more vehicle can be accomodated in this platoon. We do not need
				 * to consider intra-platoon spacing as it is already considered in the above
				 * expression.
				 */
				if((tempVar = pLenVRoads[i] % (ip.intraPlatoonDist + ip.vehicleLen)) >= ip.vehicleLen)
					platoonSizeVRoads[i] += 1;
//#if DDEBUG
				Console.WriteLine("Platoon Length on NS{0} Road = {1} Number of Vehicles in Platoon = {2}", i, pLenVRoads[i], platoonSizeVRoads[i]);
//#endif
			}
			for(int i = 0; i < eHRoads.Length; i++)
			{
				pLenHRoads[i] = ip.speedLimit * eHRoads[i] - ip.lengthW;

				/**
				 * Compute how many vehicles can fit in this platoon
				 */
				tempVar = pLenHRoads[i] / (ip.intraPlatoonDist + ip.vehicleLen);
				platoonSizeHRoads[i] = tempVar;

				if(pLenHRoads[i] % (ip.intraPlatoonDist + ip.vehicleLen) >= ip.vehicleLen)
					platoonSizeHRoads[i] += 1;
#if DDEBUG
                Console.WriteLine("Platoon Length on EW{0} Road = {1} Number of Vehicles in Platoon = {2}", i, pLenHRoads[i], platoonSizeHRoads[i]);
#endif
			}
			/**
			* Now we compute the time instants when NS (SN) and EW (WE) platoons cross the intersections.
			* Each time instant is the offset from the start of hyperperiod.
			*/

			crossingTimeNS = new int[ip.numHRoads * ip.numVRoads];
			crossingTimeEW = new int[ip.numHRoads * ip.numVRoads];

			Console.WriteLine("Schedule");
			for(int i = 0, j = 0; i < crossingTimeNS.Length; i++)
			{
				crossingTimeNS[i] = 0;
				crossingTimeEW[i] = eVRoads[j];
				Console.WriteLine("Intersection = {0} NS Crossing Time = {1} EW Crossing Time = {2}", i, crossingTimeNS[i], crossingTimeEW[i]);

				if(j < eVRoads.Length - 1)
					j++;
				else
					j = 0;
			}
		}
		private InputParameters ip;				// Reference to input parameter object

		/// <summary>
		/// Class Constructor
		/// </summary>
		/// <param name="_ip">InputParameters instance</param>
		public FixedSizeVariablePeriod(InputParameters _ip) : base(_ip)
		{
			double []temp1;		// Temporary variable
			this.ip = _ip;

			/**
			 * NOTE: We are setting 10 vehicles per platoon in the algorithm
			 */
			platoonSize = 10;
			platoonLen = platoonSize * ip.vehicleLen + (platoonSize - 1) * ip.intraPlatoonDist;

			/**
			 * The first step is to compute the execution time for the platoons.
			 * Execution time is computed as the total distance that a platoon must travel at speed limit on the intersection
			 * such that it's trailing end just clears the intersection. We take ceiling of that value for safety considerations.
			 */
			executionTime = (int) Math.Ceiling((ip.lengthW + platoonLen) * 1.0 / ip.speedLimit);
						
			/**
			 * Obtain arrival rate on NS and EW roads.
			 */
			ip.getArrivalRateVRoads(out temp1);

			/**
			 * Obtain the maximum arrival rate among all NS roads.
			 */
            maxArrivalRateVRoads = temp1[0];

			for(int i = 1; i < temp1.Length; i++)
			{
				if(maxArrivalRateVRoads < temp1[i])
					maxArrivalRateVRoads = temp1[i];
			}

			/**
			 * Repeat the same to get maximum arrival rate among all EW roads.
			 */
			ip.getArrivalRateHRoads(out temp1);
			maxArrivalRateHRoads = temp1[0];

			for(int i = 1; i < temp1.Length; i++)
			{
				if(maxArrivalRateHRoads < temp1[i])
					maxArrivalRateHRoads = temp1[i];
			}

			/**
			 * Now compute K and hence obtain period for NS platoons and period for EW platoons
			 */
			if(maxArrivalRateVRoads >= maxArrivalRateHRoads)
			{
				k = maxArrivalRateVRoads * 1.0 / maxArrivalRateHRoads;
				periodNS = (int) Math.Ceiling(executionTime * 1.0 * (1 + k) / k);
				periodEW = (int) Math.Ceiling(executionTime * 1.0 * (1 + k));
			}
			else
			{
				k = maxArrivalRateHRoads * 1.0 / maxArrivalRateVRoads;
				periodNS = (int) Math.Ceiling(executionTime * 1.0 * (1 + k));
				periodEW = (int) Math.Ceiling(executionTime * 1.0 * (1 + k) / k);
			}
			/**
			 * Compute hyperperiod now.
			 */
			int []tempArray = new int[2];
			tempArray[0] = periodNS;
			tempArray[1] = periodEW;
			H = ComputeLCM.LCM(tempArray);

			Console.WriteLine("Period NS = {0} Period EW = {1} H = {2} e = {3}", periodNS, periodEW, H, executionTime);

			double util; // utilization of intersection
			util = executionTime * 1.0 / periodNS + executionTime * 1.0 / periodEW;

			if(util > 1.0)
			{
				Console.WriteLine("Utilization EXCEEDS one. Actual Value = {0}", util);
			}
			computeClockSchedule();
		}