public static bool TryDoTransition(this NetworkPetri network, Item transition, out string msg) { if (!network.CanTransitionWork(transition, out msg)) { return(false); } foreach (var edgeId in transition.Edges) { var edge = network.Edges[edgeId]; var item = edge.GetOppositeItem(transition.ID); if (item == edge.Input) // input in transition, withdraw marks { item._value -= edge.Requirement; } else // output from transaction, add marks { item._value += edge.Requirement; } } msg = "OK"; return(true); }
public static bool TryDoAllTransitions(this NetworkPetri network, out string msg) { Dictionary <int, int> positionNewValues = new Dictionary <int, int>(); foreach (var transition in network.Transitions) { if (!network.CanTransitionWork(transition.Value, out msg)) { return(false); } foreach (var edgeId in transition.Value.Edges) { var edge = network.Edges[edgeId]; var item = edge.GetOppositeItem(transition.Value.ID); if (!positionNewValues.ContainsKey(item.ID)) { positionNewValues.Add(item.ID, item.Value); } if (item == edge.Input) // input in transition, withdraw marks { positionNewValues[item.ID] -= edge.Requirement; } else // output from transition, withdraw marks { positionNewValues[item.ID] += edge.Requirement; } } } foreach (var positionDelta in positionNewValues) { network.Positions[positionDelta.Key]._value = positionDelta.Value; } msg = "OK"; return(true); }