Save and load quivers (Xdialog/Zenity/&c only)
[clav.git] / quiver.h
blob3296f6d2b44a852e70e077a1f85a6289dcec5223
1 /*
2 * Copyright (c) 2016, S. Gilles <sgilles@math.umd.edu>
4 * Permission to use, copy, modify, and/or distribute this software
5 * for any purpose with or without fee is hereby granted, provided
6 * that the above copyright notice and this permission notice appear
7 * in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
13 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
14 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 /* A rational number */
20 struct rational {
21 /* Numerator */
22 int_fast8_t p;
24 /* Denominator */
25 uint_fast8_t q;
28 /* The structure for a vertex */
29 struct vertex {
30 /* A textual identifier for this vertex */
31 char *name;
33 /* Whether this vertex is `fat' or not. Expected to be 1, 2, or 3. */
34 uint_fast8_t fatness;
36 /* Drawing data: coordinates in `internal coordinates */
37 int x;
38 int y;
41 /* The cluster algebra structure */
42 struct quiver {
43 /* How many vertices there actually are in the quiver */
44 size_t v_num;
46 /* How many vertices we have allocated memory for */
47 size_t v_len;
49 /* Vertices */
50 struct vertex *v;
52 /* Edges - e_{ij} (fatness included, so E^t is not necessarily -E) */
53 struct rational *e;
55 /* For detecting if quiver_mutate() creates an edge too high */
56 unsigned int edge_weight_threshold;
59 /* Add an arrow of weight a/b from i -> j, affecting e(i,j) and e(j,i) */
60 int
61 quiver_add_to_edge(struct quiver *q, size_t i, size_t j, int_fast8_t a,
62 uint_fast8_t b, const char **out_errstr);
64 /* Add a vertex with a name and weight */
65 int
66 quiver_add_vertex(struct quiver *q, size_t *out_i, const char *name,
67 uint_fast16_t fatness, int x, int y, const char **out_errstr);
69 /* Increase or decrease the fatness of a vertex, readjusting edges as well */
70 int
71 quiver_adjust_fatness(struct quiver *q, size_t i, int_fast8_t fatness, const
72 char **out_errstr);
74 /* Delete a vertex (and all associated edges) */
75 int
76 quiver_delete_vertex(struct quiver *q, size_t i, const char **out_errstr);
78 /* Read quiver from file */
79 int
80 quiver_load_from_file(struct quiver *q, FILE *f, const char **out_errstr);
82 /* Serialize the quiver */
83 int
84 quiver_save_to_file(struct quiver *q, FILE *f, const char **out_errstr);
86 /* Set threshold: if quiver_mutate() creates an edge above, warn_out is set */
87 int
88 quiver_set_warning_threshold(struct quiver *q, unsigned int warn_threshold,
89 char **out_errstr);
91 /* Mutate the quiver at vertex k, setting warn_out if threshold is broken */
92 int
93 quiver_mutate(struct quiver *q, size_t k, int *out_warn, const
94 char **out_errstr);