Skip to content

Commit 398fcb2

Browse files
epostmarcosh
authored andcommitted
[#328] [stbx-core] Introduce modle Statebox.Core.Marking and simplify dependencies.
1 parent 3f6ffd4 commit 398fcb2

File tree

5 files changed

+57
-45
lines changed

5 files changed

+57
-45
lines changed

Diff for: halogen-petrinet-editor/src/View/Petrinet/Model.purs

+5-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import Data.Vec3 (Vec2D, Box, Vec3, minMax)
2626
import Data.Vec3 (bounds, minMaxZero) as Vec2D
2727
import Data.Vec3.Box as Box
2828

29+
import Statebox.Core.Types (PID, TID, Tokens) as Core
30+
2931
data Action pid tid ty2
3032
= LoadNet (NetInfoWithTypesAndRolesF pid tid Typedef ty2 ())
3133
| FireTransition tid
@@ -88,9 +90,9 @@ type NetInfoWithTypesAndRolesF pid tid ty ty2 r = Record (NetInfoWithTypesAndRol
8890

8991
-- types specialised to Int index ----------------------------------------------
9092

91-
type PID = Int
92-
type TID = Int
93-
type Tokens = Int
93+
type PID = Core.PID -- TODO remove this redirect; clients should import this directly
94+
type TID = Core.TID -- TODO remove this redirect; clients should import this directly
95+
type Tokens = Core.Tokens -- TODO remove this redirect; clients should import this directly
9496

9597
type Transition = TransitionF PID Tokens
9698
type Marking = MarkingF PID Tokens

Diff for: stbx-core/src/Statebox/Core/Marking.purs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module Statebox.Core.Marking
2+
( Tokens
3+
, PlaceMarkingF
4+
, TransitionF
5+
, buildTransitionMarking
6+
, buildPlaceMarkings
7+
) where
8+
9+
import Prelude
10+
import Data.Array ((:))
11+
import Data.FoldableWithIndex (foldrWithIndex)
12+
import Data.Map (Map)
13+
14+
import Data.ArrayMultiset as ArrayMultiset
15+
import Data.ArrayMultiset (ArrayMultiset)
16+
17+
--------------------------------------------------------------------------------
18+
19+
-- | TODO Duplicated from `Data.Petrinet.Representation.Dict` in #328.
20+
type Tokens = Int
21+
22+
-- | TODO Duplicated from `Data.Petrinet.Representation.Dict` in #328.
23+
type TransitionF p tok =
24+
{ pre :: Array (PlaceMarkingF p tok)
25+
, post :: Array (PlaceMarkingF p tok)
26+
}
27+
28+
-- | TODO Duplicated from `Data.Petrinet.Representation.Dict` in #328.
29+
type PlaceMarkingF p tok =
30+
{ place :: p
31+
, tokens :: tok
32+
}
33+
34+
--------------------------------------------------------------------------------
35+
36+
buildTransitionMarking :: a. Ord a => ArrayMultiset a -> ArrayMultiset a -> TransitionF a Tokens
37+
buildTransitionMarking pre post =
38+
{ pre: buildPlaceMarkings pre
39+
, post: buildPlaceMarkings post
40+
}
41+
42+
buildPlaceMarkings :: a. Ord a => ArrayMultiset a -> Array (PlaceMarkingF a Tokens)
43+
buildPlaceMarkings netMarking =
44+
foldrWithIndex (\place tokens -> (:) { place, tokens }) [] netMarkingDict
45+
where
46+
netMarkingDict :: Map a Tokens
47+
netMarkingDict = ArrayMultiset.countMap netMarking

Diff for: stbx-core/src/Statebox/Core/Transition.purs

+1-41
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,8 @@
11
module Statebox.Core.Transition where
22

3-
import Prelude
4-
import Data.Array ((:))
5-
import Data.FoldableWithIndex (foldrWithIndex)
6-
import Data.Map (Map)
7-
8-
import Data.ArrayMultiset as ArrayMultiset
9-
import Data.ArrayMultiset (ArrayMultiset)
103
import Statebox.Core.Execution (Path)
114
import Statebox.Core.Types (PID, TID)
12-
13-
--------------------------------------------------------------------------------
14-
15-
-- | TODO Duplicated from `Data.Petrinet.Representation.Dict` in #328.
16-
type TransitionF p tok =
17-
{ pre :: Array (PlaceMarkingF p tok)
18-
, post :: Array (PlaceMarkingF p tok)
19-
}
20-
21-
-- | TODO Duplicated from `Data.Petrinet.Representation.Dict` in #328.
22-
type PlaceMarkingF p tok =
23-
{ place :: p
24-
, tokens :: tok
25-
}
26-
27-
-- | TODO Duplicated from `Data.Petrinet.Representation.Dict` in #328.
28-
type Tokens = Int
29-
30-
--------------------------------------------------------------------------------
31-
32-
buildTransitionMarking :: a. Ord a => ArrayMultiset a -> ArrayMultiset a -> TransitionF a Tokens
33-
buildTransitionMarking pre post =
34-
{ pre: buildPlaceMarkings pre
35-
, post: buildPlaceMarkings post
36-
}
37-
38-
buildPlaceMarkings :: a. Ord a => ArrayMultiset a -> Array (PlaceMarkingF a Tokens)
39-
buildPlaceMarkings netMarking =
40-
foldrWithIndex (\place tokens -> (:) { place, tokens }) [] netMarkingDict
41-
where
42-
netMarkingDict :: Map a Tokens
43-
netMarkingDict = ArrayMultiset.countMap netMarking
44-
45-
--------------------------------------------------------------------------------
5+
import Statebox.Core.Marking (Tokens, TransitionF)
466

477
type Transition =
488
{ path :: Path

Diff for: stbx-core/src/Statebox/Core/Types.purs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Statebox.Core.Types
22
( module Statebox.Core.Net
3+
, module Statebox.Core.Marking
34
, module Statebox.Core.Diagram
45
, module Statebox.Core.Wiring
56
, module Statebox.Core.Wiring.Tree
@@ -9,6 +10,7 @@ module Statebox.Core.Types
910
) where
1011

1112
import Statebox.Core.Net
13+
import Statebox.Core.Marking
1214
import Statebox.Core.Diagram
1315
import Statebox.Core.Wiring
1416
import Statebox.Core.Wiring.Tree

Diff for: stbx-core/src/Statebox/Core/WiringTree.purs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import Data.Tuple.Nested ((/\))
1010

1111
import Data.ArrayMultiset (ArrayMultiset)
1212
import Data.Petrinet.Representation.NLL (ErrNetEncoding, TransitionF', fromNLL)
13-
import Statebox.Core.Transition (Glued(..), Transition, buildTransitionMarking, isInitial, isFinal)
13+
import Statebox.Core.Marking (buildTransitionMarking)
14+
import Statebox.Core.Transition (Glued(..), Transition, isInitial, isFinal)
1415
import Statebox.Core.Types (Diagram, Net, PID, TID, Wiring)
1516

1617
data WiringTree

0 commit comments

Comments
 (0)