How to Plan the Most Effective Patio Route

I am trying to draw some patio lights. Based on another question, I asked, I understand that I need an algorithm to solve the Problem of checking the route to determine the most effective route that should have light, the minimum overlapping edges are covered with lights. After some searching, I realized that perhaps something like this would be my best bet: Solving the Chinese postman algorithm with ailerization .

However, I am having problems creating a graph.

Here's what it should look like:

enter image description here

  • pink circles represent places in the structure in which I can hang lights from
  • Start is the only electrical outlet available
  • Yellow dots indicate all the lights of places that should cover

And here is what my graph looks like after the link to this post: Visualization of the distance between nodes in accordance with the weights - with R :

enter image description here

As you can see, all nodes are in the right place, but the edges are connected where they should not be connected. Here is my code:

library(igraph)
gg<-graph.ring(20)
ll=matrix(
  c( 0,0,    75.25,0,    150.5,0,    225.8125,0,    302.8125,0, 
     0,-87,                                          302.8125,-87,
     0,-173.8125,                                    302.8125,-173.8125,
     0,-260.9375,                                    302.8125,-260.9375,
     16,-384.3125,                                   302.8125,-384.3125,
     16,-435.9575,                                   302.8125,-435.9375,
     16,-525.1875, 75.25,-525.1875, 150.5,-525.1875, 225.8125,-525.1875, 302.8175,-525.1875),
  ncol=2,byrow=TRUE)
plot(gg,layout=ll)

I think this has something to do with nature graph.ring, but I cannot determine another way to determine the length of the edges of the graph without errors.

+4
source share
1 answer

, graph_from_edgelist , . , . btw!

  gg <- graph_from_edgelist(cbind(c(1:4, 6, 8, 10, 12, 14, 16:19, 1, 6, 8, 21, 12, 14, 5, 7, 9, 11, 13, 15), 
                                  c(2:5, 7, 9, 11, 13, 15, 17:20, 6, 8, 10, 12, 14, 16, 7, 9, 11, 13, 15, 20)))
  ll=matrix(
    c( 0,0,    75.25,0,    150.5,0,    225.8125,0,    302.8125,0, 
       0,-87,                                          302.8125,-87,
       0,-173.8125,                                    302.8125,-173.8125,
       0,-260.9375,                                    302.8125,-260.9375,
       16,-384.3125,                                   302.8125,-384.3125,
       16,-435.9575,                                   302.8125,-435.9375,
       16,-525.1875, 75.25,-525.1875, 150.5,-525.1875, 225.8125,-525.1875, 302.8175,-525.1875, 16, -260.9375),
    ncol=2,byrow=TRUE)
  plot(gg,layout=ll, edge.arrow.size = 0, vertex.size = c(rep(18, 20), 0),
       edge.color="orange")

node (n 21), , . , ?

enter image description here " " (, ), . , , , . , "" . , .

# load custom f(x) as in
# https://stackoverflow.com/questions/40576910/solving-chinese-postman-algorithm-with-eulerization/40596816#40596816

eulerian <- make.eulerian(gg)
eulerian$info
g <- eulerian$graph

# set the layout as before to keep the circuit formatted according to your specs
par(mfrow=c(1,2))
plot(gg,layout=ll, edge.arrow.size = 0, vertex.size = c(rep(18, 20), 0),
     edge.color="orange", main = "Proposed")
plot(g,layout=ll, edge.arrow.size = 0, vertex.size = c(rep(18, 20), 0),
     edge.color="orange", main = "Eulerized")

enter image description here

+2

Source: https://habr.com/ru/post/1683859/


All Articles