Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public static bool CanTransitionWork(this NetworkPetri network, Item transition, out string msg)
        {
            if (!network.Transitions.ContainsKey(transition.ID))
            {
                msg = $"Network doesn't contain transition with id = {transition.ID}";
                return(false);
            }

            foreach (var edgeId in transition.Edges)
            {
                var edge = network.Edges[edgeId];
                if (edge.Input.Type == ItemType.Transition)
                {
                    continue;
                }
                else if (edge.Requirement > edge.Position.Value)
                {
                    msg = $"Input on Edge[{edgeId}] can not work. Not enough points ({edge.Requirement} > {edge.Position.Value})";
                    return(false);
                }
            }

            msg = "OK";
            return(true);
        }
Ejemplo n.º 3
0
 public static bool TryDoTransition(this NetworkPetri network, int transitionId, out string msg)
 {
     if (network.Transitions.ContainsKey(transitionId))
     {
         var transition = network.Transitions[transitionId];
         return(network.TryDoTransition(transition, out msg));
     }
     else
     {
         msg = $"Network does not contain transition [ID = {transitionId}]";
         return(false);
     }
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 public PetriNetwork()
 {
     InitializeComponent();
     _network = new NetworkPetri.Model.NetworkPetri();
 }