| 1 | package Graph::PetriNet::TransitionAble; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use Class::Trait 'base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 3 | our @REQUIRES = qw(); | |||||||||
| 6 | |||||||||||
| 7 | =pod | ||||||||||
| 8 | |||||||||||
| 9 | =head1 NAME | ||||||||||
| 10 | |||||||||||
| 11 | Graph::PetriNet::TransitionAble - Trait for Petri net transition | ||||||||||
| 12 | |||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||
| 14 | |||||||||||
| 15 | { | ||||||||||
| 16 | package My::Place::TimeDepend; | ||||||||||
| 17 | use Class::Trait ( | ||||||||||
| 18 | 'Graph::PetriNet::TransitionAble' => { | ||||||||||
| 19 | exclude => [ 'ignitable', 'ignite' ] }); | ||||||||||
| 20 | ... | ||||||||||
| 21 | sub ignitable { ... } | ||||||||||
| 22 | sub ignite { ... } | ||||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||
| 26 | |||||||||||
| 27 | Petri net transition nodes carry the information when they can be triggered, how they execute and | ||||||||||
| 28 | how they move information from the incoming data nodes to the outgoing ones. | ||||||||||
| 29 | |||||||||||
| 30 | The default behavior implemented here only takes tokens from the upstream pushing them into the | ||||||||||
| 31 | downstream data nodes. | ||||||||||
| 32 | |||||||||||
| 33 | =head1 TRAIT | ||||||||||
| 34 | |||||||||||
| 35 | =head2 Methods | ||||||||||
| 36 | |||||||||||
| 37 | =over | ||||||||||
| 38 | |||||||||||
| 39 | =item B<inputs> | ||||||||||
| 40 | |||||||||||
| 41 | Configures the list of incoming data nodes. Passed in as list reference. | ||||||||||
| 42 | |||||||||||
| 43 | =cut | ||||||||||
| 44 | |||||||||||
| 45 | 10 | ▶ | sub inputs { | ||||||||
|
Subroutine
inputs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 46 | 10 | my $self = shift; | |||||||||
| 47 | 10 | $self->{_in_places} = $_[0]; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | =pod | ||||||||||
| 51 | |||||||||||
| 52 | =item B<outputs> | ||||||||||
| 53 | |||||||||||
| 54 | Configures the list of outgoing data nodes. Passed in as list reference. | ||||||||||
| 55 | |||||||||||
| 56 | =cut | ||||||||||
| 57 | |||||||||||
| 58 | 10 | ▶ | sub outputs { | ||||||||
|
Subroutine
outputs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 59 | 10 | my $self = shift; | |||||||||
| 60 | 10 | $self->{_out_places} = $_[0]; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | =pod | ||||||||||
| 64 | |||||||||||
| 65 | =item B<ignitable> | ||||||||||
| 66 | |||||||||||
| 67 | Method to check whether this particular transition can be fired. Returns a non-zero result if that | ||||||||||
| 68 | is the case. | ||||||||||
| 69 | |||||||||||
| 70 | =cut | ||||||||||
| 71 | |||||||||||
| 72 | 78 | ▶ | sub ignitable { | ||||||||
|
Subroutine
ignitable: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 73 | 78 | my $self = shift; | |||||||||
| 74 | 78 | foreach my $in (@{ $self->{_in_places} }) { | |||||||||
| 75 | 90 | ▶ | return 1 if $in->tokens; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | } | ||||||||||
| 77 | 49 | return 0; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | =pod | ||||||||||
| 81 | |||||||||||
| 82 | =item B<ignite> | ||||||||||
| 83 | |||||||||||
| 84 | Actually fire the transition. | ||||||||||
| 85 | |||||||||||
| 86 | =cut | ||||||||||
| 87 | |||||||||||
| 88 | 13 | ▶ | sub ignite { | ||||||||
|
Subroutine
ignite: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 89 | 13 | my $self = shift; | |||||||||
| 90 | 13 | ▶ | return unless $self->ignitable; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 13 | $_->incr_tokens (-1) foreach @{ $self->{_in_places} }; | |||||||||
| 92 | 13 | $_->incr_tokens (+1) foreach @{ $self->{_out_places} }; | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | =pod | ||||||||||
| 96 | |||||||||||
| 97 | =back | ||||||||||
| 98 | |||||||||||
| 99 | =head1 SEE ALSO | ||||||||||
| 100 | |||||||||||
| 101 | L<Graph::PetriNet> | ||||||||||
| 102 | |||||||||||
| 103 | =head1 AUTHOR | ||||||||||
| 104 | |||||||||||
| 105 | Robert Barta, E<lt>drrho@cpan.orgE<gt> | ||||||||||
| 106 | |||||||||||
| 107 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 108 | |||||||||||
| 109 | Copyright (C) 2009 by Robert Barta | ||||||||||
| 110 | |||||||||||
| 111 | This library is free software; you can redistribute it and/or modify it under the same terms as Perl | ||||||||||
| 112 | itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have | ||||||||||
| 113 | available. | ||||||||||
| 114 | |||||||||||
| 115 | |||||||||||
| 116 | =cut | ||||||||||
| 117 | |||||||||||
| 118 | 3 | "against all gods"; | |||||||||
| 119 | |||||||||||