Skip to content

Commit f995c9d

Browse files
committed
petri net export bug for floops
1 parent 309f5c5 commit f995c9d

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

src/main/haskell/PetriNet.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,23 @@ validateWeightedNet wnet
113113
valFailInit = "Validation failed for net. "
114114

115115

116+
debugTransition :: WTransition String -> String
117+
debugTransition (WTransition a nodeId weight)
118+
= "t" ++ a ++ ":" ++ show weight ++ "[" ++ nodeId ++ "]"
119+
120+
debugPlace :: Place String -> String
121+
debugPlace (Place a nodeId) = "p(" ++ a ++ "[" ++ nodeId ++ "] )"
122+
123+
debugEdge :: WEdge String -> String
124+
debugEdge (WToPlace a b) = debugTransition a ++ " -> " ++ debugPlace b
125+
debugEdge (WToTransition a b) = debugPlace a ++ " -> " ++ debugTransition b
126+
127+
formatWNetDebug :: WeightedNet -> String
128+
formatWNetDebug wnet =
129+
"Places: " ++ unwords ( map debugPlace (toList (wnplaces wnet)) )
130+
++ " Transitions: "
131+
++ unwords ( map debugTransition (toList(wntransitions wnet)) )
132+
++ " Edges: "
133+
++ unwords ( map debugEdge (toList (wnedges wnet) ) )
134+
116135

src/main/haskell/TPMine.hs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,7 @@ ptreeWeightedNet (NodeN Choice ptl w) pi po idp =
7575
pi po (wnmaxnodeid (last ptlr))
7676

7777
ptreeWeightedNet (Node1 FLoop x m w) pi po idp
78-
| m <= 1 = ptreeWeightedNet x pi po idp
79-
| m > 1 =
80-
let midp1 = midp (idp+1)
81-
px = ptreeWeightedNet x pi midp1 ( idp+2 )
82-
nx = ptreeWeightedNet (Node1 FLoop x (m-1) w) midp1 po
83-
( wnmaxnodeid px )
84-
in WeightedNet (unions [wnplaces px,wnplaces nx,
85-
fromList [midp1,pi,po]])
86-
(wntransitions px `union` wntransitions nx)
87-
(wnedges px `union` wnedges nx)
88-
pi po (wnmaxnodeid px)
78+
= ptreeWeightedNet (seqP (replicate (round m) x) w ) pi po idp
8979

9080
ptreeWeightedNet (Node1 PLoop x m w) pi po idp =
9181
let midp1 = midp (idp+1)

src/test/haskell/TPMineTest.hs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ lb2 = Leaf "b" 2
4848
lb3 = Leaf "b" 3
4949
lc2 = Leaf "c" 2
5050
ld2 = Leaf "d" 2
51-
loopa1 = Node1 FLoop la 1 1
5251

5352

5453
-- Tests
@@ -194,7 +193,7 @@ ttauout1 = WTransition "tauout" "t5" 1
194193
ttauout2 = WTransition "tauout" "t5" 2
195194

196195

197-
translateLoops = [
196+
translatePLoops = [
198197
"translateLoopLeaf" ~:
199198
WeightedNet (fromList [pin,pout,pmidLoop1])
200199
(fromList [tlpa4_id6, ttauin5, ttauout1])
@@ -245,7 +244,27 @@ translateLoops = [
245244
~=? translate (Node1 PLoop (NodeN Choice [la8,lb2] 10) 5 10)
246245
]
247246

248-
translateTests = translateLoops ++ translateRest
247+
248+
tla5_1 = WTransition "a" "t3" 5
249+
tla5_2 = WTransition "a" "t4" 5
250+
pfl1 = Place "" "p2"
251+
252+
translateFLoops = [
253+
"translateLoopLeaf" ~:
254+
WeightedNet (fromList [pin,pout,pfl1] )
255+
(fromList [tla5_1,tla5_2])
256+
(fromList [WToPlace tla5_1 pfl1,
257+
WToPlace tla5_2 pout,
258+
WToTransition pfl1 tla5_2,
259+
WToTransition pin tla5_1 ])
260+
pin pout 4
261+
~=? translate (Node1 FLoop la5 2 5),
262+
"translateLoopLeaf3" ~:
263+
translate (NodeN Seq [la5,la5,la5] 5)
264+
~=? translate (Node1 FLoop la5 3 5)
265+
]
266+
267+
translateTests = translatePLoops ++ translateFLoops ++ translateRest
249268

250269
validationTests = [
251270
"validNet1" ~: valOk

0 commit comments

Comments
 (0)