Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ExperimentalUnsignedTypes
- fun main() {
- // val random = MersenneTwister(2)
- System.setProperty("org.graphstream.ui", "swing")
- val nodes = 400
- val maxSize = 20
- val minSize = 7
- val graphs = (0..0).map {
- SingleGraph("asda").also { graph ->
- val layout = SpringBox(false, Random(1))
- with(LobsterGenerator(2, 10)) {
- addNodeLabels(false)
- setRandomSeed(0)
- addSink(graph)
- addSink(layout)
- begin()
- (0..nodes).forEach { _ ->
- nextEvents()
- }
- end()
- }
- val degrees = graph.map { it.edges().count() }
- val maxDeg = degrees.maxOrNull() ?: 0
- val minDeg = degrees.minOrNull() ?: 0
- fun Long.scaled() = minSize + (this - minDeg) * (maxSize - minSize) / (maxDeg - minDeg)
- graph.forEach { it.setAttribute("ui.style", "size: ${it.edges().count().scaled()}px;") }
- // graph.display(false)
- var count = 0u
- while (layout.stabilization < 1) {
- layout.compute()
- count++
- }
- println(count)
- graph.forEach {
- val coordinates = it.getAttribute("xyz")
- if (coordinates is Array<*>) {
- val actualCoordinates = coordinates.filterIsInstance<Double>()
- println("${it.index} -> $actualCoordinates")
- it.setAttribute("x", actualCoordinates[0])
- it.setAttribute("y", actualCoordinates[1])
- } else {
- throw IllegalStateException("Unexpected type ${coordinates::class}, an array was expected")
- }
- }
- graph.display(false)
- }
- }
- println(graphs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement