@@ -49,10 +49,6 @@ interface IGF<G: IGraph<G, E, V>, E: IEdge<G, E, V>, V: IVertex<G, E, V>> {
49
49
}
50
50
)
51
51
52
- // TODO: generify, only works for labeled graphs
53
- fun G (graph : String ): G =
54
- graph.split(" " ).fold(G ()) { acc, it -> acc + G (it.toCharArray().toList()) }
55
-
56
52
// Gafter's gadget! http://gafter.blogspot.com/2006/12/super-type-tokens.html
57
53
private fun gev (): Array <Class <* >> =
58
54
(generateSequence(javaClass) { it.superclass as Class <IGF <G , E , V >> }
@@ -83,11 +79,16 @@ interface IGraph<G, E, V>: IGF<G, E, V>, Set<V>, (V) -> Set<V>
83
79
* - Pros: Useful for describing many algebraic path problems
84
80
* - Cons: Esoteric API / unsuitable as an abstract interface
85
81
*
86
- * Algebraic perspective : https://github.com/snowleopard/alga-paper/releases/download/final/algebraic-graphs.pdf
87
- * Type-family perspective : https://www.cs.cornell.edu/~ross/publications/shapes/shapes-pldi14-tr.pdf#page=3
88
- * Inductive perspective : https://web.engr.oregonstate.edu/~erwig/papers/InductiveGraphs_JFP01.pdf
89
- * Mathematical perspective : https://doi.org/10.1007/978-0-387-75450-5
90
- * Semiring perspective : http://stedolan.net/research/semirings.pdf
82
+ * Algebraic perspective : https://github.com/snowleopard/alga-paper/releases/download/final/algebraic-graphs.pdf
83
+ * : https://arxiv.org/pdf/1909.04881.pdf
84
+ * Type-family perspective : https://www.cs.cornell.edu/~ross/publications/shapes/shapes-pldi14-tr.pdf#page=3
85
+ * : https://www.cs.cornell.edu/andru/papers/familia/familia.pdf#page=8
86
+ * Inductive perspective : https://web.engr.oregonstate.edu/~erwig/papers/InductiveGraphs_JFP01.pdf
87
+ * : https://doi.org/10.1145/258949.258955
88
+ * : https://www.cs.utexas.edu/~wcook/Drafts/2012/graphs.pdf
89
+ * Semiring perspective : http://stedolan.net/research/semirings.pdf
90
+ * : https://doi.org/10.1007/978-0-387-75450-5
91
+ * : https://doi.org/10.2200/S00245ED1V01Y201001CNT003
91
92
*/
92
93
93
94
where G : IGraph <G , E , V >, E : IEdge <G , E , V >, V : IVertex <G , E , V > {
@@ -134,6 +135,9 @@ interface IEdge<G, E, V>: IGF<G, E, V>
134
135
val source: V
135
136
val target: V
136
137
138
+ operator fun component1 () = source
139
+ operator fun component2 () = target
140
+
137
141
fun render (): Link = (source.render() - target.render()).add(Label .of(" " ))
138
142
}
139
143
@@ -146,8 +150,8 @@ interface IVertex<G, E, V>: IGF<G, E, V>, Encodable
146
150
val outgoing: Set <E > get() = edgeMap(this as V ).toSet()
147
151
val edgeMap: (V ) -> Set <E > // Make a self-loop by passing this
148
152
149
- open val neighbors get() = outgoing.map { it.target }.toSet()
150
- open val outdegree get() = neighbors.size
153
+ val neighbors get() = outgoing.map { it.target }.toSet()
154
+ val outdegree get() = neighbors.size
151
155
152
156
// tailrec prohibited on open members? may be possible with deep recursion
153
157
// https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-deep-recursive-function/
@@ -181,6 +185,6 @@ infix fun Collection<Any>.allAre(that: Any) = all { it isA that }
181
185
infix fun Collection<Any>.anyAre (that : Any ) = any { it isA that }
182
186
183
187
// https://github.com/amodeus-science/amod
184
- // abstract class Map : IGraph<Map, Road, City >
185
- // abstract class Road : IEdge<Map, Road, City >
186
- // abstract class City : IVertex<Map, Road, City >
188
+ abstract class TMap : IGraph <TMap , TRoad , TCity >
189
+ abstract class TRoad : IEdge <TMap , TRoad , TCity >
190
+ abstract class TCity : IVertex <TMap , TRoad , TCity >
0 commit comments