Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Mates,
I need to solve a TSP Problem, with the distances info given as follows
I was trying to solve it by using dictionaries but I can't figure it out:
**Actually, dont even know how to post code as text here (just got 2 days with Python)
Any advide/help would be more than wellcome.
Thanks!
You can do sth like this:
import numpy as np
TT= np.array([[0,5,2,13,4],
[3,0,6,3,14],
[2,6,0,4,5],
[2,3,7,0,8],
[4,2,5,5,0]])
# assume we start in node 0
currentStop = 0
routeList = [0]
for _i in range(len(TT)-1):
TT[:,currentStop] = 100000 # Set column of visited stop to very large number
currentStop = np.argmin(TT[currentStop,:])
routelist.append(currentStop)
print(routelist)
TSP is an NP-hard problem, which means it's computationally hard to obtain the optimal result. It is possible to try all routes when the data size is small, but in practice we have thousands of nodes (nodes are locations in a TSP problem). Then we would use different searching algorithms to obtain a sub-optimal solution in reasonable time.
Since you are using Python I'd suggest you take a look at ortools. You can take a look at their simple examples to get started. It is written in C with a Python wrapper so it is much faster than pure Python.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
I am working on a problem but can not quite categorize it.
The problem consist of putting some items on a grid.
Each edge between an item and another item gives a certain benefit and is supposed to be placed such that I get the maximum possible sum of benefits for the particular configuration of that grid.
The grid itself has some coordinates that can not contain an item.(such as a wall)
It is also allowed not to place some items.
Can I get some guidance on how to go about it?
Algorithm, process of going about the problem, data structure to use or any relevant information.
Unfortunately I can't make the question any clearer.
Thanks
Here are my high-level thoughts on this.
So, this is sounding to me like a graph problem. Each item in your "item bank" will become a node in the graph. You then make edges between the nodes, and then assign a weight (integer value) to an edge based on how beneficial the relationship is between the two nodes the edge connects.
Once you've set up the graph, you could then implement a maximum flow algorithm. Of course, this would also require that you set up "source" and "sink" nodes. The maximum flow you get would then represent the maximum benefit.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 11 months ago.
Improve this question
I'm trying to clean the line noises from this captcha, so I can implement an algorithm to read them. However, I'm finding some difficulties to make it readable to an AI using some techniques, such as Open CV threshold combined with some resources from pil.Image. I also tried an algorithm to "chop" the image, which gave me a better results, but stil far from the expected. I want to know if there is an alternative to remove noises from captchas like this one effectively.
(I'm using python)
Initially, the Captcha looks like this:
Once processed using OpenCV + Pillow, I've got this:
Later, using the "chop method" this what we have:
However, I need a better final image, but I think this methods combination is not appropriate. Is there a better alternative?
I think you could try minisom: https://github.com/JustGlowing/minisom
SOM (Self organizes maps) are a type of neural networks that group clusters of points in data, with an appropiate threshold it could help you removing those lines that are not surrounding the numbers/letters, combining that with chop method could do the job.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have a few lists of movement tracking data, which looks something like this
I want to create a list of outputs where I mark these large spikes, essentially telling that there is a movement at that point.
I applied a rolling standard deviation on the data with a window size of two and got this result
Now I can see the spikes which mark the point of interest, but I am not sure how to do it in code. A statistical tool to measure these spikes, which can be used to flag these spikes.
There are several approaches that you can use for an anomaly detection task.
The choice depends on your data.
If you want to use a statistical approach, you can use some measures like z-score or IQR.
Here you can find a tutorial for these measures.
Here instead, you can find another tutorial for a statistical approach which uses mean and variance.
Last but not least, I suggest you also to check how to use a control chart, because in some cases it's enough.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am wondering what I should do for the purpose of my project.
I am gonna operate on about 100 000 rows, every time.
what I wanted to do is to create an object "{}" and then, if I need to search for a value, just call it , for example
data['2018']['09']['Marketing']['AccountName']
the second option is to pull everyting into an array "[]" and in case I need to pull value, I will create a function to go through the array and sum numbers for specific parameters.
But don't know which method is faster.
Will be thankful if you can shed some light on this
Thanks in advance,
If performance (speed) is an issue, Python might not be the ideal choice...
Otherwise:
Might I suggest the use of a proper database, such as SQLLite (which comes shipped with Python).
And maybe SQLAlchemy as an abstraction layer. (https://docs.sqlalchemy.org/en/latest/orm/tutorial.html)
After all, they were made exactly for this kind of tasks.
If that seems overkill: Have a look at Pandas.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
for example:
a=1500
b=[500,400,200]
One answer is:
ans=[1,2,1]
because 1*500+2*400+1*200=1500 I want to write a program with genetic algorithm with best evaluation function to solve this problem with this array with pyevolve python evolutionary tool.
Assuming that the coefficients in the answer must be integers, what you're describing is a linear Diophantine equation. It's not a good fit for a genetic algorithm, as the solution space is neither continuous nor smooth. (That is, there is not always a possible input between any two other inputs, and the "correct" answer will not necessarily be anywhere near other nearly-correct inputs.)
(If the coefficients in the answer can be real numbers, finding a solution is trivial to the point that a genetic algorithm would be overkill.)