-
Notifications
You must be signed in to change notification settings - Fork 0
/
dijkstra.frg
618 lines (566 loc) · 21 KB
/
dijkstra.frg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
#lang forge "final" "kg6EYhEuRtzmnKAu"
// option verbose 10
// stores info about Dijkstra's explore progress
sig State {
next: lone State,
/* A function from a node to a *sequence* of nodes; represents the shortest path
that Dijkstra's has found from the start to this node at a given state;
the sequence is none when a node has not yet been explored */
paths: pfunc Node -> Int -> Node,
/* each node has a total current path length at a given state; this is none
when a node has not yet been explored */
pathLengths: pfunc Node -> Int
}
// stores info about the starting node for Dijkstra's and the goal node
one sig Traverse {
start : one Node,
end : one Node
}
// the nodes of the graph
sig Node {
/* a set of int, node pairs representing all outgoing edges from the current node;
the int is the weight of that edge and the node is the node that this edges connects
the current node to */
edges: set Int -> Node
}
/* This function creates a virtual "visited" field for the State sig that stores all
the nodes that have been visited at a given state. It pulls its info from whether
or the pathLength for a node exists at a given state. This enables syntax like "State0.visited" */
fun visited: set State -> Node {
{s: State, n: Node | #{i : Int | n -> i in pathLengths[s]} > 0}
}
/* This function creates a virtual "neighbors" field for the Node sig that stores
a set of nodes that a given node has as neighbors; enables syntax like "Node0.neighbors" */
fun neighbors: set Node -> Node {
{n1, n2: Node | some w: Int | n1 -> w -> n2 in edges}
}
// get the weight of the edge going from n1 to n2
fun getEdgeWeight(n1: Node, n2: Node): lone Int {
{i: Int | n1 -> i -> n2 in edges}
}
// enforces a connected graph; every node is reachable from every other node
pred connected {
all disj n1, n2 : Node | reachable[n1, n2, neighbors]
}
// makes directed graphs a bit more interesting: no two nodes each connect to each other
pred noMutualEdges {
all n1, n2 : Node | {
n2 in n1.neighbors implies not n1 in n2.neighbors
}
}
// makes a graph undirected--every neighbor relationship is reciprocated
pred undirected {
all n1, n2 : Node | {
getEdgeWeight[n1, n2] = getEdgeWeight[n2, n1]
}
}
// makes nodes unable to be their own neighbor
pred noSelfNeighbor {
all n1: Node | not n1 in n1.neighbors
}
// makes the graph a tree
pred tree {
// there is one node such that every other node is reachable from that node
one n: Node | {
all n2: Node | n != n2 implies {
reachable[n2, n, neighbors]
// each node that's not the top of the tree has some parent
one n3: Node | {
n2 in n3.neighbors
}
// no node connects to the top
n not in n2.neighbors
}
}
noSelfNeighbor
}
// makes every weight positive
pred positiveWeights {
all i: {i: Int | some n1, n2: Node | n1 -> i -> n2 in edges} | {
i > 0
}
}
pred wellformed {
// at most one connection to any node
// (all n1, n2: Node | {
// // WARNING: OVERFLOW CAN HAPPEN, ENSURE BITWIDTH IS GOOD
// let numEdgesFromN1ToN2 = #{i: Int | n1 -> i -> n2 in edges} | {
// numEdgesFromN1ToN2 = 0 or numEdgesFromN1ToN2 = 1
// }
// })
// new way of writing this that causes fewer overflow issues
(all n1, n2: Node | {
lone i: Int | {
n1 -> i -> n2 in edges
}
})
// enforce that each path is a sequence
all s: State, n: Node | {
isSeqOf[s.paths[n], Node]
}
}
// determines whether there is an edge from n1 to n2
pred edgeExists[n1: Node, n2: Node] {
some {i: Int | n1 -> i -> n2 in edges}
}
pred init[s: State] {
// set up non-start Node values
all n : Node | (n != Traverse.start) implies {
// the path sequence for all nodes except the start is empty
isEmpty[s.paths[n]]
no s.pathLengths[n]
}
// starting path is initialized to 0, with only itself as path
let startPathSeq = s.paths[Traverse.start] | {
// the only element in the start's path is the starting element
elems[startPathSeq] = Traverse.start
#inds[startPathSeq] = 1
s.pathLengths[Traverse.start] = 0
}
}
pred canTransition[pre: State, post: State] {
// post is pre's next
pre.next = post
// candidates is the set of edges that connect a node inside the visited set to a node outside the visited set
let candidates = {n1: Node, i: Int, n2: Node | (n1 in pre.visited) and (n2 not in pre.visited) and (n1 -> i -> n2 in edges)} |
// the set of proposed new path lengths; that is, all the lengths that a candidate node could have
// if an edge were added to it from inside the visited set
let newPathLengths = {i: Int | {
// find some pair of nodes that are in the candidates set
some n1, n2: Node | some {i: Int | n1 -> i -> n2 in candidates} and {
// the new pathLength for n2 would be the pathLength of n1 + the weight of that edge
let newLen = add[pre.pathLengths[n1], getEdgeWeight[n1, n2]] | {
newLen = i
}
}
}} |
let minNewPathLength = min[newPathLengths] |
let edgesCreatingMinPath = {n1: Node, i: Int, n2: Node | (n1 -> i -> n2 in candidates) and add[pre.pathLengths[n1], getEdgeWeight[n1, n2]] = minNewPathLength} |
let newNodes = edgesCreatingMinPath[Node][Int] | {
some newNode: Node | newNode in newNodes and {
// pathLengths and paths remain unchanged for nodes that are not newNode
all n: Node | n != newNode implies {
pre.pathLengths[n] = post.pathLengths[n]
pre.paths[n] = post.paths[n]
}
post.pathLengths[newNode] = minNewPathLength
let oldNode = {n: Node | some i: Int | n -> i -> newNode in edgesCreatingMinPath} |
let newPath = post.paths[newNode] |
let oldPath = pre.paths[oldNode] | {
newPath = oldPath + ((#inds[oldPath]) -> newNode)
}
}
}
}
pred final[s: State] {
// end is in visited set
Traverse.end in s.visited
all pre: State | reachable[s, pre, next] implies not (Traverse.end in pre.visited)
}
pred doNothing[pre: State, post: State] {
all n: Node | {
pre.pathLengths[n] = post.pathLengths[n]
pre.paths[n] = post.paths[n]
}
}
pred TransitionStates {
some initState, finalState: State {
-- no state has init as its next state, fulfills init requirements
no prev: State | prev.next = initState
init[initState]
final[finalState]
-- if final has future states, they are do nothing
all post1, post2: State | {
(reachable[post2, finalState, next] and post2 = post1.next) implies {doNothing[post1, post2]}
}
-- link init to final state via next
not final[initState] implies reachable[finalState, initState, next]
-- valid transitions before final state
all s: State | {(s != finalState and not reachable[s, finalState, next]) implies canTransition[s, s.next]}
}
}
// equivalent of final, but for Explore
pred finalExplore[s: State] {
all n: Node | reachable[n, Traverse.start, neighbors] implies {
n in s.visited
}
all pre: State | reachable[s, pre, next] implies not {
all n: Node | reachable[n, Traverse.start, neighbors] implies {
n in pre.visited
}
}
}
// an alternative to TransitionStates that just explores until it has found everything it can, not stopping at Traverse.end
pred Explore {
some initState, finalState: State {
-- no state has init as its next state, fulfills init requirements
no prev: State | prev.next = initState
init[initState]
// final[finalState]
finalExplore[finalState]
-- if final has future states, they are do nothing
all post1, post2: State | {
(reachable[post2, finalState, next] and post2 = post1.next) implies {doNothing[post1, post2]}
}
-- link init to final state via next
reachable[finalState, initState, next]
-- valid transitions before final state
all s: State | {(s != finalState and not reachable[s, finalState, next]) implies canTransition[s, s.next]}
}
}
pred nice {
connected
noSelfNeighbor
positiveWeights
}
pred smallWeights {
all n1, n2: Node | {
let weight = getEdgeWeight[n1, n2] | {
some weight implies weight < 5
}
}
}
// Example blocks
// check a sample transition
example validTransition is {some pre, post: State | canTransition[pre, post]} for {
State = `S0 + `S1
Node = `Node0 + `Node1
Traverse = `Traverse0
edges = `Node0 -> 4 -> `Node1
start = `Traverse0 -> `Node0
end = `Traverse0 -> `Node1
next = `S0 -> `S1
paths = `S0 -> `Node0 -> 0 -> `Node0 +
`S1 -> `Node0 -> 0 -> `Node0 +
`S1 -> `Node1 -> 0 -> `Node0 +
`S1 -> `Node1 -> 1 -> `Node1
pathLengths = `S0 -> `Node0 -> 0 +
`S1 -> `Node0 -> 0 +
`S1 -> `Node1 -> 4
}
// if doesn't follow shortest path, fails transitions
example chooseWrongPath is not {some pre, post: State | canTransition[pre, post]} for {
State = `S0 + `S1
Node = `Node0 + `Node1 + `Node2 + `Node3
Traverse = `Traverse0
edges = `Node0 -> 1 -> `Node1 +
`Node0 -> 7 -> `Node2 +
`Node1 -> 1 -> `Node3 +
`Node2 -> 7 -> `Node1 +
`Node2 -> 7 -> `Node3
start = `Traverse0 -> `Node0
end = `Traverse0 -> `Node3
next = `S0 -> `S1
paths = `S0 -> `Node0 -> 0 -> `Node0 +
`S1 -> `Node0 -> 0 -> `Node0 +
`S1 -> `Node2 -> 0 -> `Node0 +
`S1 -> `Node2 -> 1 -> `Node2
pathLengths = `S0 -> `Node0 -> 0 +
`S1 -> `Node0 -> 0 +
`S1 -> `Node2 -> 7
}
// can complete a zigzag graph
example completesZigzag is TransitionStates for {
State = `S0 + `S1 + `S2 + `S3
Node = `Node0 + `Node1 + `Node2 + `Node3
Traverse = `Traverse0
edges = `Node0 -> 4 -> `Node1 +
`Node0 -> 8 -> `Node2 +
`Node1 -> 8 -> `Node3 +
`Node1 -> 1 -> `Node2 +
`Node2 -> 1 -> `Node1 +
`Node2 -> 3 -> `Node3
start = `Traverse0 -> `Node0
end = `Traverse0 -> `Node3
next = `S0 -> `S1 +
`S1 -> `S2 +
`S2 -> `S3
paths = `S0 -> `Node0 -> 0 -> `Node0 +
`S1 -> `Node0 -> 0 -> `Node0 +
`S1 -> `Node1 -> 0 -> `Node0 +
`S1 -> `Node1 -> 1 -> `Node1 +
`S2 -> `Node0 -> 0 -> `Node0 +
`S2 -> `Node1 -> 0 -> `Node0 +
`S2 -> `Node1 -> 1 -> `Node1 +
`S2 -> `Node2 -> 0 -> `Node0 +
`S2 -> `Node2 -> 1 -> `Node1 +
`S2 -> `Node2 -> 2 -> `Node2 +
`S3 -> `Node0 -> 0 -> `Node0 +
`S3 -> `Node1 -> 0 -> `Node0 +
`S3 -> `Node1 -> 1 -> `Node1 +
`S3 -> `Node2 -> 0 -> `Node0 +
`S3 -> `Node2 -> 1 -> `Node1 +
`S3 -> `Node2 -> 2 -> `Node2 +
`S3 -> `Node3 -> 0 -> `Node0 +
`S3 -> `Node3 -> 1 -> `Node1 +
`S3 -> `Node3 -> 2 -> `Node2 +
`S3 -> `Node3 -> 3 -> `Node3
pathLengths = `S0 -> `Node0 -> 0 +
`S1 -> `Node0 -> 0 +
`S1 -> `Node1 -> 4 +
`S2 -> `Node0 -> 0 +
`S2 -> `Node1 -> 4 +
`S2 -> `Node2 -> 5 +
`S3 -> `Node0 -> 0 +
`S3 -> `Node1 -> 4 +
`S3 -> `Node2 -> 5 +
`S3 -> `Node3 -> 8
#Int = 5
}
// can complete wheel graph from center
example completesWheelFromCenter is TransitionStates for {
State = `S0 + `S1
Node = `Node0 + `Node1 + `Node2 + `Node3 + `Node4
Traverse = `Traverse0
edges = `Node0 -> 1 -> `Node1 +
`Node0 -> 1 -> `Node2 +
`Node0 -> 1 -> `Node3 +
`Node0 -> 1 -> `Node4 +
`Node1 -> 1 -> `Node2 +
`Node2 -> 1 -> `Node3 +
`Node3 -> 1 -> `Node4 +
`Node4 -> 1 -> `Node1
start = `Traverse0 -> `Node0
end = `Traverse0 -> `Node1
next = `S0 -> `S1
paths = `S0 -> `Node0 -> 0 -> `Node0 +
`S1 -> `Node0 -> 0 -> `Node0 +
`S1 -> `Node1 -> 0 -> `Node0 +
`S1 -> `Node1 -> 1 -> `Node1
pathLengths = `S0 -> `Node0 -> 0+
`S1 -> `Node0 -> 0 +
`S1 -> `Node1 -> 1
}
// can complete wheel graph from edge
example completesWheelFromEdge is TransitionStates and Explore for {
State = `S0 + `S1 + `S2 + `S3
Node = `Node0 + `Node1 + `Node2 + `Node3 + `Node4
Traverse = `Traverse0
edges = `Node0 -> 1 -> `Node1 +
`Node0 -> 1 -> `Node2 +
`Node0 -> 1 -> `Node3 +
`Node0 -> 1 -> `Node4 +
`Node1 -> 1 -> `Node2 +
`Node2 -> 1 -> `Node3 +
`Node3 -> 1 -> `Node4 +
`Node4 -> 1 -> `Node1
start = `Traverse0 -> `Node1
end = `Traverse0 -> `Node4
next = `S0 -> `S1 +
`S1 -> `S2 +
`S2 -> `S3
paths = `S0 -> `Node1 -> 0 -> `Node1 +
`S1 -> `Node1 -> 0 -> `Node1 +
`S1 -> `Node2 -> 0 -> `Node1 +
`S1 -> `Node2 -> 1 -> `Node2 +
`S2 -> `Node1 -> 0 -> `Node1 +
`S2 -> `Node2 -> 0 -> `Node1 +
`S2 -> `Node2 -> 1 -> `Node2 +
`S2 -> `Node3 -> 0 -> `Node1 +
`S2 -> `Node3 -> 1 -> `Node2 +
`S2 -> `Node3 -> 2 -> `Node3 +
`S3 -> `Node1 -> 0 -> `Node1 +
`S3 -> `Node2 -> 0 -> `Node1 +
`S3 -> `Node2 -> 1 -> `Node2 +
`S3 -> `Node3 -> 0 -> `Node1 +
`S3 -> `Node3 -> 1 -> `Node2 +
`S3 -> `Node3 -> 2 -> `Node3 +
`S3 -> `Node4 -> 0 -> `Node1 +
`S3 -> `Node4 -> 1 -> `Node2 +
`S3 -> `Node4 -> 2 -> `Node3 +
`S3 -> `Node4 -> 3 -> `Node4
pathLengths = `S0 -> `Node1 -> 0 +
`S1 -> `Node1 -> 0 +
`S1 -> `Node2 -> 1 +
`S2 -> `Node1 -> 0 +
`S2 -> `Node2 -> 1 +
`S2 -> `Node3 -> 2 +
`S3 -> `Node1 -> 0 +
`S3 -> `Node2 -> 1 +
`S3 -> `Node3 -> 2 +
`S3 -> `Node4 -> 3
#Int = 5
}
// Starting state is final state passes
example startingIsFinal is TransitionStates for {
State = `S0 + `S1
next = `S0 -> `S1
Node = `Node0 + `Node1 + `Node2 + `Node3
Traverse = `Traverse0
start = `Traverse0 -> `Node0
end = `Traverse0 -> `Node0
edges = `Node0 -> 1 -> `Node1 +
`Node1 -> 1 -> `Node2 +
`Node2 -> 1 -> `Node3
paths = `S0 -> `Node0 -> 0 -> `Node0 +
`S1 -> `Node0 -> 0 -> `Node0
pathLengths = `S0 -> `Node0 -> 0 +
`S1 -> `Node0 -> 0
}
// every node is connected
example allConnectedNodes is TransitionStates for {
State = `S0 + `S1 + `S2
Node = `Node0 + `Node1 + `Node2
Traverse = `Traverse0
edges = `Node0 -> 1 -> `Node1 +
`Node0 -> 1 -> `Node2 +
`Node1 -> 1 -> `Node0 +
`Node1 -> 1 -> `Node2 +
`Node2 -> 1 -> `Node0 +
`Node2 -> 1 -> `Node1
start = `Traverse0 -> `Node0
end = `Traverse0 -> `Node2
next = `S0 -> `S1 +
`S1 -> `S2
paths = `S0 -> `Node0 -> 0 -> `Node0 +
`S1 -> `Node0 -> 0 -> `Node0 +
`S1 -> `Node1 -> 0 -> `Node0 +
`S1 -> `Node1 -> 1 -> `Node1 +
`S2 -> `Node0 -> 0 -> `Node0 +
`S2 -> `Node1 -> 0 -> `Node0 +
`S2 -> `Node1 -> 1 -> `Node1 +
`S2 -> `Node2 -> 0 -> `Node0 +
`S2 -> `Node2 -> 1 -> `Node2
pathLengths = `S0 -> `Node0 -> 0 +
`S1 -> `Node0 -> 0 +
`S1 -> `Node1 -> 1 +
`S2 -> `Node0 -> 0 +
`S2 -> `Node1 -> 1 +
`S2 -> `Node2 -> 1
}
// negative weights fails
example negativeWeights is not TransitionStates for {
State = `S0 + `S1 + `S2
Node = `Node0 + `Node1 + `Node2
Traverse = `Traverse0
edges = `Node0 -> -1 -> `Node1 +
`Node0 -> -1 -> `Node2 +
`Node1 -> -1 -> `Node0 +
`Node1 -> -1 -> `Node2 +
`Node2 -> -1 -> `Node0 +
`Node2 -> -1 -> `Node1
start = `Traverse0 -> `Node0
end = `Traverse0 -> `Node2
next = `S0 -> `S1 +
`S1 -> `S2
paths = `S0 -> `Node0 -> 0 -> `Node0 +
`S1 -> `Node0 -> 0 -> `Node0 +
`S1 -> `Node1 -> 0 -> `Node0 +
`S1 -> `Node1 -> 1 -> `Node1 +
`S2 -> `Node0 -> 0 -> `Node0 +
`S2 -> `Node1 -> 0 -> `Node0 +
`S2 -> `Node1 -> 1 -> `Node1 +
`S2 -> `Node2 -> 0 -> `Node0 +
`S2 -> `Node2 -> 1 -> `Node2
pathLengths = `S0 -> `Node0 -> 0 +
`S1 -> `Node0 -> 0 +
`S1 -> `Node1 -> -1 +
`S2 -> `Node0 -> 0 +
`S2 -> `Node1 -> -1 +
`S2 -> `Node2 -> -1
}
// disconnected node fails nice predicate
example disconnectedNode is not nice for {
State = `S0 + `S1 + `S2 + `S3
Node = `Node0 + `Node1 + `Node2 + `Node3 + `Node4
Traverse = `Traverse0
edges = `Node0 -> 4 -> `Node1 +
`Node0 -> 8 -> `Node2 +
`Node1 -> 8 -> `Node3 +
`Node1 -> 1 -> `Node2 +
`Node2 -> 1 -> `Node1 +
`Node2 -> 3 -> `Node3
start = `Traverse0 -> `Node0
end = `Traverse0 -> `Node3
next = `S0 -> `S1 +
`S1 -> `S2 +
`S2 -> `S3
paths = `S0 -> `Node0 -> 0 -> `Node0 +
`S1 -> `Node0 -> 0 -> `Node0 +
`S1 -> `Node1 -> 0 -> `Node0 +
`S1 -> `Node1 -> 1 -> `Node1 +
`S2 -> `Node0 -> 0 -> `Node0 +
`S2 -> `Node1 -> 0 -> `Node0 +
`S2 -> `Node1 -> 1 -> `Node1 +
`S2 -> `Node2 -> 0 -> `Node0 +
`S2 -> `Node2 -> 1 -> `Node1 +
`S2 -> `Node2 -> 2 -> `Node2 +
`S3 -> `Node0 -> 0 -> `Node0 +
`S3 -> `Node1 -> 0 -> `Node0 +
`S3 -> `Node1 -> 1 -> `Node1 +
`S3 -> `Node2 -> 0 -> `Node0 +
`S3 -> `Node2 -> 1 -> `Node1 +
`S3 -> `Node2 -> 2 -> `Node2 +
`S3 -> `Node3 -> 0 -> `Node0 +
`S3 -> `Node3 -> 1 -> `Node1 +
`S3 -> `Node3 -> 2 -> `Node2 +
`S3 -> `Node3 -> 3 -> `Node3
pathLengths = `S0 -> `Node0 -> 0 +
`S1 -> `Node0 -> 0 +
`S1 -> `Node1 -> 4 +
`S2 -> `Node0 -> 0 +
`S2 -> `Node1 -> 4 +
`S2 -> `Node2 -> 5 +
`S3 -> `Node0 -> 0 +
`S3 -> `Node1 -> 4 +
`S3 -> `Node2 -> 5 +
`S3 -> `Node3 -> 8
#Int = 5
}
test expect {
vacuous: {wellformed} is sat
vacuousWithDijkstra: {
wellformed
TransitionStates
} is sat
travelToDisconnectedImpossible: {
wellformed
positiveWeights
// no incoming edges to some node that is the ending node
some n: Node | {
all n2: Node | n != n2 implies not edgeExists[n2, n]
Traverse.end = n
Traverse.start != n
}
TransitionStates
} for {next is linear} is unsat
numVisitedIncreasesByZeroOrOne: {
wellformed
positiveWeights
TransitionStates
not (all s1, s2: State | s1.next = s2 implies {
((#(s1.visited)) = (#(s2.visited))) or
(add[(#(s1.visited)), 1] = (#(s2.visited)))
})
} for {next is linear} is unsat
// if a connected graph is explored, it will find every node every time
connectedAlwaysHasSolution: {
wellformed
connected
not(Explore implies {
some s: State | {
s.visited = Node
}
})
} for {next is linear} is unsat
pathFoundIffReachable: {
wellformed
Explore
not(all n: Node | {
// a path will be found if and only if the node is the start or it's reachable
(reachable[n, Traverse.start, neighbors] or n = Traverse.start) iff {
some s: State | {
n in s.visited
}
}
})
} for {next is linear} is unsat
}
run {
wellformed
nice
TransitionStates
(#edges) < 15
smallWeights
Traverse.start != Traverse.end
} for exactly 5 Node, exactly 6 Int, exactly 5 State for {next is linear}