|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace PTNetSimulator
{
/// <summary>
/// Represents a Transition in a P/T net
/// </summary>
public class Transition : IComparable<Transition>
{
#region XML data
/// <summary>
/// The name of the transition
/// </summary>
[XmlAttribute]
public string Name { get; set; }
/// <summary>
/// The method associated with the transition
/// </summary>
[XmlAttribute]
public string MethodName { get; set; }
/// <summary>
/// The weight associated with the transition during MCST
/// Value must be positive but does not need to be normalized
/// The value is interpreted as the relative probability against all other weights in the network
/// </summary>
[XmlAttribute]
public double Weight;
/// <summary>
/// Comma-separated list of input places
/// </summary>
[XmlElement]
public string InputPlacesCSV { get; set; }
/// <summary>
/// Comma-separated list of output places
/// </summary>
[XmlElement]
public string OutputPlacesCSV { get; set; }
#endregion XML data
public Transition()
{
Rank = -1;
}
#region Properties
/// <summary>
/// Places to supply input
/// </summary>
[XmlIgnore]
public string[] InputPlaces
{
get
{
if (inputPlaces == null)
{
inputPlaces = InputPlacesCSV.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(n => n.Trim()).ToArray();
}
return inputPlaces;
}
}
private string[] inputPlaces = null;
/// <summary>
/// Places to receive output
/// </summary>
[XmlIgnore]
public string[] OutputPlaces
{
get
{
if (outputPlaces == null)
{
outputPlaces = OutputPlacesCSV.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(n => n.Trim()).ToArray();
}
return outputPlaces;
}
}
private string[] outputPlaces = null;
/// <summary>
/// The rank of the transition. The value -1 signals an unranked transition
/// </summary>
[XmlIgnore]
public int Rank { get; set; }
/// <summary>
/// The method associated with the transition
/// </summary>
public Delegate Method { get; set; }
#endregion Properties
#region MCST
/// <summary>
/// Actual number of executions
/// </summary>
[XmlIgnore]
public int CountActualExecution { get; private set; }
/// <summary>
/// Requested number of executions
/// </summary>
[XmlIgnore]
public int CountRequestedExecution { get; private set; }
/// <summary>
/// Increments actual execution count
/// </summary>
public void IncrExecutionCount()
{
++CountActualExecution;
}
/// <summary>
/// Requests execution.
/// </summary>
/// <returns>True if the transition must be executed, false if it has already been executed as part of a dependency resolution</returns>
public bool MSCT_RequestExecution()
{
++CountRequestedExecution;
return CountRequestedExecution > CountActualExecution;
}
/// <summary>
/// Resets CountActualExecution and CountRequestedExecution
/// </summary>
public void ClearExecutionCounts()
{
CountActualExecution = 0;
CountRequestedExecution = 0;
}
#endregion MCST
#region IComparable<Transition>
/// <summary>
/// Sort by rank then name
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public int CompareTo(Transition other)
{
int result = Rank.CompareTo(other.Rank);
if (result == 0)
{
result = Name.CompareTo(other.Name);
}
return result;
}
#endregion IComparable<Transition>
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I started programming as a kid and went through basic, C and assembler. I got a MSc.CS from University of Aarhus in 1998 and have maintained an interest for computer science ever since, that I enjoy applying to the problems I come across. I have worked in different roles as a programmer, architect, project manager and consulting in many different areas including databases, cryptography, server architecture and distributed systems. I am currently focussing on the testing done during development and seek to improve this through a combination of approach, skill and technology.