main
test-branch
|
Last change
on this file since bb03188 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago |
|
Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
1.5 KB
|
| Rev | Line | |
|---|
| [a999c3f] | 1 | #include "treebuffer.h"
|
|---|
| 2 | #include <stdlib.h>
|
|---|
| 3 |
|
|---|
| 4 | // bounded number of new nodes that will be added
|
|---|
| 5 | $input int N;
|
|---|
| 6 | $assume(0 < N && N <= 5);
|
|---|
| 7 | $input int HISTORY_SIZE;
|
|---|
| 8 | $assume(0 < HISTORY_SIZE && HISTORY_SIZE < N);
|
|---|
| 9 | $input int Data[N];
|
|---|
| 10 | // the non-deterministic pick of an existing tree as a parent
|
|---|
| 11 | $input int TreePicks[N + 1];
|
|---|
| 12 | $assume($forall (int i : 0 .. N) 0 <= TreePicks[i] && TreePicks[i] <= i);
|
|---|
| 13 | // all possible results: N iterations * trace-size
|
|---|
| 14 | $output int Traces[N][HISTORY_SIZE];
|
|---|
| 15 |
|
|---|
| 16 | void write_to_output(int iter, Node * history[]) {
|
|---|
| 17 | // read trace:
|
|---|
| 18 | int h = 0;
|
|---|
| 19 |
|
|---|
| 20 | for (; h < HISTORY_SIZE; h++)
|
|---|
| 21 | if (history[h] != 0)
|
|---|
| 22 | Traces[iter][h] = get_data(history[h]);
|
|---|
| 23 | else
|
|---|
| 24 | break;
|
|---|
| 25 | // make all unused elements -1 in Traces:
|
|---|
| 26 | for (; h < HISTORY_SIZE; h++)
|
|---|
| 27 | Traces[iter][h] = -1;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | int main() {
|
|---|
| 31 | Tree * tree = empty(HISTORY_SIZE);
|
|---|
| 32 | Tree * forest[N + 1]; // N new tree + the empty tree
|
|---|
| 33 | int num_trees = 0;
|
|---|
| 34 |
|
|---|
| 35 | $elaborate(N);
|
|---|
| 36 | forest[num_trees++] = tree;
|
|---|
| 37 | while (num_trees <= N) {
|
|---|
| 38 | tree = forest[TreePicks[num_trees-1]];
|
|---|
| 39 | $elaborate(TreePicks[num_trees-1]);
|
|---|
| 40 | $atomic{
|
|---|
| 41 | Tree * new_tree = add(tree, Data[num_trees-1]);
|
|---|
| 42 |
|
|---|
| 43 | forest[num_trees++] = new_tree;
|
|---|
| 44 | tree = new_tree;
|
|---|
| 45 | }
|
|---|
| 46 | $atomic{
|
|---|
| 47 | Node * history[HISTORY_SIZE + 1]; // 0-terminated array (i.e. extra element at the end as 0)
|
|---|
| 48 | int h = 0;
|
|---|
| 49 |
|
|---|
| 50 | take(tree, history);
|
|---|
| 51 | write_to_output(num_trees - 2, history);
|
|---|
| 52 | }
|
|---|
| 53 | }
|
|---|
| 54 | // delete forest
|
|---|
| 55 | for (int i = 0; i < num_trees; i++)
|
|---|
| 56 | delete(forest[i]);
|
|---|
| 57 | return 0;
|
|---|
| 58 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.