Graph Coloring with using Simulated Annealing

浪尽此生 提交于 2019-12-22 13:58:51

问题


I am trying to come up with the algorithm for a Graph Coloring problem using Simulated Annealing. There is the general algorithm online, but when i look at it, I couldn't understand how can apply this algorithm on this problem. Each node in graph must had diffrent color from it's neibours.

How can I use the Simulated annealing algorithm for this.
What is the "temperature", "schedule" in this problem?

Please help me understand this. Thanks


回答1:


Setting the starting temperature and cooling scheduling parameters correctly is a pain, because you need to have a good value for both before you get a good result. If one of them is off, then you might not notice that you're changing the other one in the good direction.

That's why I applied a trick to calculate the cooling scheduling based on the other parameter (the starting temperature) and the time gradient (a number that's 0.0 at the start and 1.0 after the time limit is reached). It's a lot easier to tune 1 parameter to a good value.

Generally, I advice to start with a starting temperature of the average score diff in all your moves (=neighborhood).




回答2:


A proper coloring of a graph is an assignment of colors to the vertices of the graph so that no two adjacent vertices have the same color.
To solve this problem assume you have a graph G with N nodes then you need these methods:

  • assignColor(graph): for first result
  • assignColor(graph, node): to set a new color for a nod
  • isColoringValid(graph): to check current coloring is valid or not
  • lossFunction(graph): calculate the number of colors which is used
  • getProbability( oldValue, newValue, temperature) : calculate the new state is accepted or not

Finally write a recursive method as simulatedAnnealing(graph, temp) which contains a main loop to change color for each node then check isColoringValid() if it would ok calculate loss function() and getProbability(). Because in higher temperature you can accept worth answer but in lower temperature, only better answer is accepted and at the end of method reduce the temperature and call simulatedAnnealing(graph, temp).

You can find complete solution in my github.



来源:https://stackoverflow.com/questions/51635658/graph-coloring-with-using-simulated-annealing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!