Skip to content

Commit 31071e6

Browse files
kore-repl: In the graph visualizer add no. of nodes on dotted edges (#2944)
* kore-repl: In the graph visualizer add no. of nodes on dotted edges * Use data EdgeLabel Co-authored-by: rv-jenkins <[email protected]>
1 parent 96c6f44 commit 31071e6

File tree

3 files changed

+74
-42
lines changed

3 files changed

+74
-42
lines changed

kore/src/Kore/Repl/Interpreter.hs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ showGraph view mfile out = do
490490
processedGraph <-
491491
case view of
492492
Just Expanded ->
493-
return $ Graph.emap Just graph
493+
return $ Graph.emap IndividualLabel graph
494494
_ ->
495495
maybe (showOriginalGraph graph) return (smoothOutGraph graph)
496496
installed <- liftIO Graph.isGraphvizInstalled
@@ -507,7 +507,7 @@ showGraph view mfile out = do
507507
putStrLn'
508508
"Could not process execution graph for visualization.\
509509
\ Will default to showing the full graph."
510-
return $ Graph.emap Just graph
510+
return $ Graph.emap IndividualLabel graph
511511

512512
-- | Executes 'n' prove steps, or until branching occurs.
513513
proveSteps ::
@@ -1448,7 +1448,7 @@ printNotFound = putStrLn' "Variable or index not found"
14481448
showDotGraph ::
14491449
From axiom AttrLabel.Label =>
14501450
From axiom RuleIndex =>
1451-
Gr CommonClaimState (Maybe (Seq axiom)) ->
1451+
Gr CommonClaimState (EdgeLabel (Seq axiom)) ->
14521452
IO ()
14531453
showDotGraph gr =
14541454
flip Graph.runGraphvizCanvas' Graph.Xlib
@@ -1459,7 +1459,7 @@ showDotGraph gr =
14591459
showDotGraphCatchException ::
14601460
From axiom AttrLabel.Label =>
14611461
From axiom RuleIndex =>
1462-
Gr CommonClaimState (Maybe (Seq axiom)) ->
1462+
Gr CommonClaimState (EdgeLabel (Seq axiom)) ->
14631463
IO ()
14641464
showDotGraphCatchException gr =
14651465
catch (showDotGraph gr) $ \(e :: GraphvizException) ->
@@ -1479,7 +1479,7 @@ showDotGraphCatchException gr =
14791479
saveDotGraph ::
14801480
From axiom AttrLabel.Label =>
14811481
From axiom RuleIndex =>
1482-
Gr CommonClaimState (Maybe (Seq axiom)) ->
1482+
Gr CommonClaimState (EdgeLabel (Seq axiom)) ->
14831483
Graph.GraphvizOutput ->
14841484
FilePath ->
14851485
IO ()
@@ -1499,17 +1499,17 @@ saveDotGraph gr format file =
14991499
graphParams ::
15001500
From axiom AttrLabel.Label =>
15011501
From axiom RuleIndex =>
1502-
Gr CommonClaimState (Maybe (Seq axiom)) ->
1502+
Gr CommonClaimState (EdgeLabel (Seq axiom)) ->
15031503
Graph.GraphvizParams
15041504
Graph.Node
15051505
CommonClaimState
1506-
(Maybe (Seq axiom))
1506+
(EdgeLabel (Seq axiom))
15071507
()
15081508
CommonClaimState
15091509
graphParams gr =
15101510
Graph.nonClusteredParams
15111511
{ Graph.fmtEdge = \(_, resN, l) ->
1512-
[ Graph.textLabel (maybe "" (ruleIndex resN) l)
1512+
[ Graph.textLabel (eitherEdgeLabel nrOfNodes (ruleIndex resN) l)
15131513
, Graph.Attr.Style [dottedOrSolidEdge l]
15141514
]
15151515
, Graph.fmtNode = \(_, ps) ->
@@ -1521,9 +1521,13 @@ graphParams gr =
15211521
]
15221522
}
15231523
where
1524+
nrOfNodes :: Natural -> Text.Lazy.Text
1525+
nrOfNodes quantity
1526+
| quantity < 1 = ""
1527+
| otherwise = "(" <> Text.Lazy.pack (show quantity) <> " nodes omitted)"
15241528
dottedOrSolidEdge lbl =
1525-
maybe
1526-
(Graph.Attr.SItem Graph.Attr.Dotted mempty)
1529+
eitherEdgeLabel
1530+
(const $ Graph.Attr.SItem Graph.Attr.Dotted mempty)
15271531
(const $ Graph.Attr.SItem Graph.Attr.Solid mempty)
15281532
lbl
15291533
ruleIndex resultNode lbl =

kore/src/Kore/Repl/State.hs

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ License : BSD-3-Clause
66
Maintainer : [email protected]
77
-}
88
module Kore.Repl.State (
9+
EdgeLabel (..),
10+
eitherEdgeLabel,
11+
ommitedNodes,
12+
individualLabel,
913
emptyExecutionGraph,
1014
getClaimByIndex,
1115
getAxiomByIndex,
@@ -80,6 +84,7 @@ import Data.Graph.Inductive.PatriciaTree (
8084
import qualified Data.Graph.Inductive.Query.DFS as Graph
8185
import Data.List.Extra (
8286
findIndex,
87+
genericLength,
8388
groupSort,
8489
)
8590
import Data.Map.Strict (
@@ -340,13 +345,13 @@ updateExecutionGraph gph = do
340345
with its edges pointed "downwards" (from the root)
341346
and is partially ordered (parent(node) < node).
342347
-}
343-
smoothOutGraph :: Gr node edge -> Maybe (Gr node (Maybe edge))
348+
smoothOutGraph :: Gr node edgeLabel -> Maybe (Gr node (EdgeLabel edgeLabel))
344349
smoothOutGraph graph = do
345350
let subGraph = Graph.nfilter inOutDegreeOne graph
346351
edgesToAdd <-
347352
traverse (componentToEdge subGraph) (Graph.components subGraph)
348353
let nodesToRemove = Graph.nodes subGraph
349-
liftedSubGraph = Graph.emap Just (Graph.delNodes nodesToRemove graph)
354+
liftedSubGraph = Graph.emap IndividualLabel (Graph.delNodes nodesToRemove graph)
350355
liftedGraph = Graph.insEdges edgesToAdd liftedSubGraph
351356
return liftedGraph
352357
where
@@ -356,32 +361,54 @@ smoothOutGraph graph = do
356361
&& Graph.indeg graph node == 1
357362
&& not (all isBranchingNode $ Graph.pre graph node)
358363
componentToEdge ::
359-
Gr node edge ->
364+
Gr node edgeLabel ->
360365
[Graph.Node] ->
361-
Maybe (Graph.LEdge (Maybe edge))
366+
Maybe (Graph.LEdge (EdgeLabel edgeLabel))
362367
componentToEdge subGraph nodes =
363368
case filter (isTerminalNode subGraph) nodes of
364-
[node] -> makeNewEdge node node
369+
[node] -> makeNewEdge node 1 node
365370
[node1, node2] ->
366371
if node1 < node2
367-
then makeNewEdge node1 node2
368-
else makeNewEdge node2 node1
372+
then makeNewEdge node1 (genericLength nodes) node2
373+
else makeNewEdge node2 (genericLength nodes) node1
369374
_ -> Nothing
370375
makeNewEdge ::
371376
Graph.Node ->
377+
Natural ->
372378
Graph.Node ->
373-
Maybe (Graph.LEdge (Maybe edge))
374-
makeNewEdge node1 node2 = do
379+
Maybe (Graph.LEdge (EdgeLabel edgeLabel))
380+
makeNewEdge node1 nrOfNodes node2 = do
375381
nodePre <- headMay (Graph.pre graph node1)
376382
nodeSuc <- headMay (Graph.suc graph node2)
377-
return (nodePre, nodeSuc, Nothing)
383+
return (nodePre, nodeSuc, OmmitedNodes nrOfNodes)
378384
isBranchingNode :: Graph.Node -> Bool
379385
isBranchingNode node =
380386
Graph.outdeg graph node > 1
381-
isTerminalNode :: Gr node edge -> Graph.Node -> Bool
387+
isTerminalNode :: Gr node edgeLabel -> Graph.Node -> Bool
382388
isTerminalNode graph' node =
383389
Graph.indeg graph' node == 0 || Graph.outdeg graph' node == 0
384390

391+
data EdgeLabel individualLabel
392+
= OmmitedNodes Natural
393+
| IndividualLabel individualLabel
394+
deriving stock (Eq, Ord)
395+
396+
eitherEdgeLabel ::
397+
(Natural -> a) ->
398+
(individualLabel -> a) ->
399+
EdgeLabel individualLabel ->
400+
a
401+
eitherEdgeLabel f _ (OmmitedNodes quantity) = f quantity
402+
eitherEdgeLabel _ g (IndividualLabel label) = g label
403+
404+
ommitedNodes :: EdgeLabel individualLabel -> Natural
405+
ommitedNodes (OmmitedNodes quantity) = quantity
406+
ommitedNodes _ = error "EdgeLabel.ommitedNodes: IndividualLabel"
407+
408+
individualLabel :: EdgeLabel individualLabel -> individualLabel
409+
individualLabel (IndividualLabel label) = label
410+
individualLabel _ = error "EdgeLabel.individualLabel: OmmitedNodes"
411+
385412
{- | Returns the first interesting branching node encountered by
386413
exploring the proof graph for 'n' steps over all branches, starting
387414
from 'node'. If no such node exists, it tries to return the only existing

kore/test/Test/Kore/Repl/Graph.hs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Data.Set (
1515
)
1616
import qualified Data.Set as Set
1717
import Kore.Repl.State (
18+
EdgeLabel (..),
1819
smoothOutGraph,
1920
)
2021
import Prelude.Kore
@@ -159,7 +160,7 @@ tree2 =
159160
, (4, 11)
160161
]
161162

162-
g1', g2', chain', tree1', tree2' :: Gr () (Maybe ())
163+
g1', g2', chain', tree1', tree2' :: Gr () (EdgeLabel ())
163164
g1' = fromJust $ smoothOutGraph g1
164165
g2' = fromJust $ smoothOutGraph g2
165166
chain' = fromJust $ smoothOutGraph chain
@@ -171,16 +172,16 @@ expectedG1'
171172
, expectedChain'
172173
, expectedTree1'
173174
, expectedTree2' ::
174-
Gr () (Maybe ())
175+
Gr () (EdgeLabel ())
175176
expectedG1' = Graph.mkGraph [(1, ())] []
176177
expectedG2' =
177178
Graph.mkGraph
178179
[(1, ()), (2, ())]
179-
[(1, 2, Just ())]
180+
[(1, 2, IndividualLabel ())]
180181
expectedChain' =
181182
Graph.mkGraph
182183
[(0, ()), (100, ())]
183-
[(0, 100, Nothing)]
184+
[(0, 100, OmmitedNodes 99)]
184185
expectedTree1' =
185186
Graph.mkGraph
186187
[ (0, ())
@@ -195,16 +196,16 @@ expectedTree1' =
195196
, (10, ())
196197
, (13, ())
197198
]
198-
[ (0, 1, Just ())
199-
, (1, 2, Just ())
200-
, (1, 3, Just ())
201-
, (2, 5, Nothing)
202-
, (5, 6, Just ())
203-
, (5, 7, Just ())
204-
, (5, 8, Just ())
205-
, (6, 9, Just ())
206-
, (8, 10, Just ())
207-
, (3, 13, Nothing)
199+
[ (0, 1, IndividualLabel ())
200+
, (1, 2, IndividualLabel ())
201+
, (1, 3, IndividualLabel ())
202+
, (2, 5, OmmitedNodes 1)
203+
, (5, 6, IndividualLabel ())
204+
, (5, 7, IndividualLabel ())
205+
, (5, 8, IndividualLabel ())
206+
, (6, 9, IndividualLabel ())
207+
, (8, 10, IndividualLabel ())
208+
, (3, 13, OmmitedNodes 2)
208209
]
209210
expectedTree2' =
210211
Graph.mkGraph
@@ -217,11 +218,11 @@ expectedTree2' =
217218
, (10, ())
218219
, (9, ())
219220
]
220-
[ (0, 1, Just ())
221-
, (0, 2, Just ())
222-
, (0, 3, Just ())
223-
, (0, 4, Just ())
224-
, (2, 10, Nothing)
225-
, (3, 9, Nothing)
226-
, (4, 11, Just ())
221+
[ (0, 1, IndividualLabel ())
222+
, (0, 2, IndividualLabel ())
223+
, (0, 3, IndividualLabel ())
224+
, (0, 4, IndividualLabel ())
225+
, (2, 10, OmmitedNodes 3)
226+
, (3, 9, OmmitedNodes 1)
227+
, (4, 11, IndividualLabel ())
227228
]

0 commit comments

Comments
 (0)