Adaptagrams
quadaction.h
1 /*
2  * vim: ts=4 sw=4 et tw=0 wm=0
3  *
4  * libdialect - A library for computing DiAlEcT layouts:
5  * D = Decompose/Distribute
6  * A = Arrange
7  * E = Expand/Emend
8  * T = Transform
9  *
10  * Copyright (C) 2018 Monash University
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  * See the file LICENSE.LGPL distributed with the library.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21  *
22  * Author(s): Steve Kieffer <http://skieffer.info>
23 */
24 
25 #ifndef DIALECT_QUADACTION_H
26 #define DIALECT_QUADACTION_H
27 
28 #include <string>
29 #include <vector>
30 
31 #include "libdialect/commontypes.h"
32 
33 namespace dialect {
34 
50 std::vector<std::string> lookupQuadActions(size_t p, size_t q, size_t r, size_t s, size_t c);
51 
56 const std::vector<unsigned> SEMIAXIS_SETS_BY_CARDINALITY[5] = {
57  {0},
58  {1, 2, 4, 8},
59  {3, 5, 9, 6, 10, 12},
60  {14, 13, 11, 7},
61  {15}
62 };
63 
65 struct Nbr {
66 
73  Nbr(id_type id, double dx, double dy);
74 
79  unsigned octalCode(void) const;
80 
86  double deflection(void) const;
87 
88  id_type id;
89  double x;
90  double y;
91 };
92 
95 struct Assignment {
96 
106  Assignment(const Nbrs &semis, double cost) : semis(semis), cost(cost) {}
107 
111  Assignment(void) : semis({nullptr, nullptr, nullptr, nullptr}), cost(0) {}
112 
115  size_t cardinality(void) const;
116 
125  Assignment makeUnion(const Assignment &other) const;
126 
132  std::string toString(void) const;
133 
134  Nbrs semis;
135  double cost;
136 };
137 
139 struct Quad {
140 
144  Quad(unsigned num);
145 
147  void addNbr(const Nbr_SP &nbr) { nbrs.push_back(nbr); }
148 
150  size_t size(void) const { return nbrs.size(); }
151 
156  void sortAndComputeCosts(void);
157 
168  Assignment constructAssignmentForAction(char action) const;
169 
171  unsigned num;
173  Nbrs nbrs;
175  double ACost;
177  double CCost;
178 };
179 
181 struct Arrangement {
182 
186  Arrangement(Nbrs nbrs);
187 
192  std::vector<unsigned> vacancy(void) const;
193 
197  std::vector<unsigned> dist(void) const;
198 
203  std::vector<unsigned> rDist(void) const;
204 
210  Assignment_SP getBasicAssignment(void) const;
211 
219  Assignment_SP getAssignmentForQuadAction(std::string quadAction) const;
220 
227  Assignments computeNAssignments(unsigned N) const;
228 
235  Assignments computeAllAssignments(void) const;
236 
238  Nbrs nbrs;
240  Nbrs semis;
242  Quads quads;
243 };
244 
245 
246 } // namespace dialect
247 
248 #endif // DIALECT_QUADACTION_H
Assignment makeUnion(const Assignment &other) const
Create union of two Assignments.
Definition: quadaction.cpp:80
std::string toString(void) const
Write a string representation, listing the id of the Nbr assigned to each semiaxis. For example if Nbrs 3, 7, 8 are assigned to semiaxes E, S, N resp., represent this as "3 7 - 8".
Definition: quadaction.cpp:95
const std::vector< unsigned > SEMIAXIS_SETS_BY_CARDINALITY[5]
Definition: quadaction.h:56
std::vector< unsigned > rDist(void) const
Get the "reduced distribution vector" for this Arrangement.
Definition: quadaction.cpp:192
std::vector< unsigned > dist(void) const
Get the "distribution vector" for this Arrangement.
Definition: quadaction.cpp:184
Assignment(const Nbrs &semis, double cost)
Standard constructor.
Definition: quadaction.h:106
libdialect: A library for computing human-like orthogonal network (DiAlEcT) layouts.
Definition: cola.h:44
std::vector< std::string > lookupQuadActions(size_t p, size_t q, size_t r, size_t s, size_t c)
Look up legal quad actions.
Definition: qalookup.cpp:204
Assignment constructAssignmentForAction(char action) const
Construct an Assignment indicating which Nbr(s) were assigned to which semiaxes, and representing the...
Definition: quadaction.cpp:134
double deflection(void) const
A measure of how far into its quadrant this nbr lies, in the clockwise direction. ...
Definition: quadaction.cpp:59
Nbrs nbrs
The Nbrs that lie in this quadrant.
Definition: quadaction.h:173
Nbrs semis
The semiaxes.
Definition: quadaction.h:240
Represents the arrangement of all Nbrs around a centre node.
Definition: quadaction.h:181
Represents a neighbouring node to a central node.
Definition: quadaction.h:65
void addNbr(const Nbr_SP &nbr)
Add a neighbour.
Definition: quadaction.h:147
Nbr(id_type id, double dx, double dy)
Standard constructor.
Definition: quadaction.cpp:41
Assignments computeNAssignments(unsigned N) const
Compute all possible Assignments in which precisely N semiaxes are occupied, sorted by ascending cost...
Definition: quadaction.cpp:222
double ACost
Cost for anticlockwise action.
Definition: quadaction.h:175
unsigned num
The number of this quadrant, 0, 1, 2, or 3.
Definition: quadaction.h:171
double CCost
Cost for clockwise action.
Definition: quadaction.h:177
Quad(unsigned num)
Standard constructor.
Definition: quadaction.cpp:110
std::vector< unsigned > vacancy(void) const
Get the "vacancy vector" for this Arrangement.
Definition: quadaction.cpp:174
size_t size(void) const
Say how many Nbrs are in this quadrant.
Definition: quadaction.h:150
unsigned octalCode(void) const
Definition: quadaction.cpp:49
Represents an assignment of nbrs to semiaxes, and records the cost of this assignment.
Definition: quadaction.h:95
Nbrs nbrs
All Nbrs in the Arrangement.
Definition: quadaction.h:238
Quads quads
The quadrants.
Definition: quadaction.h:242
void sortAndComputeCosts(void)
To be called after all nbrs have been added. Sorts the nbrs into clockwise order, and then computes a...
Definition: quadaction.cpp:115
Assignments computeAllAssignments(void) const
Compute all possible Assignments.
Definition: quadaction.cpp:287
Represents a quadrant, relative to a central node.
Definition: quadaction.h:139
Assignment_SP getBasicAssignment(void) const
Get the "basic Assignment" for this Arrangement.
Definition: quadaction.cpp:203
Assignment_SP getAssignmentForQuadAction(std::string quadAction) const
Get the Assignment resulting from a given quad action.
Definition: quadaction.cpp:209
size_t cardinality(void) const
Return the "cardinality" of this Assignment, i.e. the number of Nbrs assigned to semiaxes.
Definition: quadaction.cpp:68
Arrangement(Nbrs nbrs)
Standard constructor.
Definition: quadaction.cpp:152
Assignment(void)
Default constructor.
Definition: quadaction.h:111