Documentation
¶
Index ¶
- Constants
- func Is(err error, code ErrCode) bool
- type Cfg
- type CfgTransition
- type Consumer
- type ErrCode
- type Error
- type Factory
- type Net
- func (c *Net) AddPlace(place *Place) error
- func (c *Net) AddTransition(transition *Transition) error
- func (c *Net) AsGraphvizDotLang(name string, withState bool) (string, error)
- func (c *Net) FullReset()
- func (c *Net) GetErrFromState() *Error
- func (c *Net) GetPlace(placeID string) (*Place, error)
- func (c *Net) GetState() State
- func (c *Net) IsErrState() bool
- func (c *Net) IsFinished() bool
- func (c *Net) SetConsumer(l Consumer)
- func (c *Net) SetErrorState(err *Error) error
- func (c *Net) SetPlace(placeID string) error
- func (c *Net) SetStartPlace(place string) error
- func (c *Net) StartPlace() error
- func (c *Net) UpFromState(state State)
- type Place
- type Pool
- type PoolNet
- type State
- type Transition
Constants ¶
const DefaultPoolTimeout time.Duration = 30 * time.Second
DefaultPoolTimeout is default timeout for poll get.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cfg ¶
type Cfg struct {
Start string `json:"start"`
Finish []string `json:"finish"`
Places []string `json:"places"`
Transitions map[string]CfgTransition `json:"transitions"`
}
Cfg is config for petri network.
type CfgTransition ¶
CfgTransition is struct of transition.
type Consumer ¶
type Consumer interface {
BeforePlace(placeID string) error
AfterPlace(placeID string)
CanTransit(transitionID string) bool
BeforeTransit(transitionID string) error
AfterTransit(transitionID string)
}
Consumer is interface for external consumer.
type ErrCode ¶
type ErrCode int
const ( ErrCodePlaceAlreadyRegistered ErrCode = iota + 1 ErrCodeTransitionAlreadyRegistered ErrCodePlaceIsNotRegistered ErrCodeUnexpectedAvailableTransitionsNumber ErrCodeHasNotChipForNewPlace ErrCodeNetInErrState ErrCodeBeforePlaceReturnedErr ErrCodeBeforeTransitReturnedErr ErrCodeCantSetErrState ErrCodeFinished ErrCodeFromTransitionAlreadyRegistered ErrCodeToTransitionAlreadyRegistered ErrCodeConsumerNotSet ErrCodePoolAlreadyInit ErrCodeWaitingForNetFromPoolTooLong )
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
Factory fro net with prepared buffer.
func NewFactory ¶
NewFactory init factory.
type Net ¶
type Net struct {
// contains filtered or unexported fields
}
Net of petri net.
func (*Net) AddTransition ¶
func (c *Net) AddTransition(transition *Transition) error
AddTransition tp petri net.
func (*Net) AsGraphvizDotLang ¶
AsGraphvizDotLang return string with graphviz dot lang view of graph. If u set 'withState', you will have chips on graph. 'turquoise' is color for start place, 'sienna' is coor for finish places. 'red' is for chips on map.
func (*Net) GetErrFromState ¶
GetErrFromState return err state reason.
func (*Net) IsFinished ¶
IsFinished return info about state, finished or not.
func (*Net) SetErrorState ¶
SetStartPlace by name of state.
func (*Net) SetPlace ¶
SetPlace for chip. If chip in finish place, will return true as first result.
func (*Net) SetStartPlace ¶
SetStartPlace by name of state.
func (*Net) UpFromState ¶
UpFromState set current state for work.
type Place ¶
type Place struct {
ID string
ToTransitions []*Transition
FromTransition *Transition
IsFinished bool
}
Place of chip in net.
func (*Place) AddToTransitions ¶
func (s *Place) AddToTransitions(transition *Transition) error
AddToTransitions to place in net.
func (*Place) SetFromTransition ¶
func (s *Place) SetFromTransition(transition *Transition) error
SetFromTransition to place in net.
type PoolNet ¶
type PoolNet struct {
*Net
// contains filtered or unexported fields
}
PoolNet is wrapper of net for pool.
type State ¶
type State struct {
Finished bool `json:"finished"`
Err *Error `json:"err"`
PlaceChips map[string]int `json:"place_chips"`
TransitionChips map[string]int `json:"transition_chips"`
}
State is current state of net, contains places for chips in places and transitions.
type Transition ¶
Transition model of net.