Simulated-Annealing | TSP, 旅行商, 模拟退火
kandi X-RAY | Simulated-Annealing Summary
kandi X-RAY | Simulated-Annealing Summary
TSP, 旅行商, 模拟退火
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Simulated-Annealing
Simulated-Annealing Key Features
Simulated-Annealing Examples and Code Snippets
def simulated_annealing(
search_prob,
find_max: bool = True,
max_x: float = math.inf,
min_x: float = -math.inf,
max_y: float = math.inf,
min_y: float = -math.inf,
visualization: bool = False,
start_temperate: float = 1
Community Discussions
Trending Discussions on Simulated-Annealing
QUESTION
I am implementing an android application using different geographic coordinates and I need to solve a problem similar to the traveling salesman.
I found an implementation of the algorithm at http://www.theprojectspot.com/tutorial-post/simulated-annealing-algorithm-for-beginners/6.
I adjusted the code to what I need, and it produces theoretically optimal results. I noticed, however, that each execution produces a different type of result.
I went back to the original code and found that even in the original, there is disagreement as to the results.
Do not understand. Shouldn't the result be unique? After all, we are looking for the smallest path ... perhaps some small variation, but each execution differs by several units from the previous execution.
How could I adjust the algorithm to produce the same result in all runs? Has anyone worked with this?
...ANSWER
Answered 2020-Jan-31 at 19:18That's the price you pay for an algorithm like this one: the results obtained might very well be different every time. The algorithm does not "find the shortest path," which is a computationally intractable problem ("travelling salesman"). Instead, it seeks to quickly find a solution that is "short enough." Whether or not it actually does so depends very much on the data ... and, to a non-trivial degree, on random chance.
And, since the algorithm is comparatively fast, sometimes you do run it several times in a row in order to gauge the variability of the solutions obtained. If (say) three runs each produce results that are "close enough" to one another, there's a good chance that the result is reliable. But if the standard deviation is very large, the algorithm might not be giving you a good answer. (Bear in mind that sometimes the solution will be wrong.)
So to speak: "you get what you pay for, but you don't pay much for it, and of course that is the point."
QUESTION
I just realized I made a mistake in an algorithm I wrote years ago.
Instead of r < p in this flow, what I did was checking if p <= r. Honestly, I cannot put my mind together to decide if this is a huge mistake or not.
...ANSWER
Answered 2019-Sep-24 at 02:57P
becomes smaller and smaller as the temperature rises. When you check for r < p
it becomes increasingly unlikely that your search will switch from the current state to a worse new state. This is the idea of Simulated Annealing.
You check for p <= r
, which makes it increasingly likely that your search will switch to a worse state in the end and less likely at the beginning. I assume you will get very mixed results with this as you are doing exploitation first and exploration later.
QUESTION
I am trying to implement n-queens problems using simulated annealing
. I have looked up at all the existing problems and it doesn't solve my problem. The code that I have come up with is this
ANSWER
Answered 2017-Aug-30 at 20:39There are several issues with your code. To start with, your generateNextState
function is fundamentally broken. It has both design and implementation issues.
Lets handle the implementation issue first. The function modifies state
in place, before also returning it. That's not good since you're passing the current state in, and then later comparing the new state with the old one (which is not very useful if they're the same object). The function should probably make a copy of the input.
The design issue is that it creates a new state that is completely random. The new state has no relation to the previous state. That's bad since it means your search is just picking values at random and seeing if you eventually guess a solution. You should pick a new state that is closely related to the old state. For instance, you could try moving a random queen to a random row:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Simulated-Annealing
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page