Solution search solved using DFS or Greedy BFS? [closed] - python

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 6 years ago.
Improve this question
I have a problem that sounds like this: A company has 4 taxis in 4 different (A B C D) locations. 4 people (W X Y Z) call the company that they need a taxi. I need to find the fastest way that the taxis can arrive at their people knowing that a taxi can only go for 1 person and each taxi has assigned a value between its destination and the people's destinations.
I was thinking of building a tree with all the possible combinations ex: AW-BX-CY-DZ or AX-BW-CY-DZ etc and find the minimum cost for each of them but I need to solve this using the DFS or greedy BFS approach. Any ideas how this would work? I can't imagine it.
I just want the idea on how to solve this using DFS/GBFS. I can't figure out how it would have to go or when the search would end since I'm looking for the minimum distance used

This is an instance of an assignment problem, which is finding maximum/minimum weight matching in a weighted bipartite graph. Most common algorithm used to solve this kind of problem is the Hungarian Algorithm, solving it in O(n^3). There is a Python module implementing it - munkres.
However, If You really want to use DFS/BFS You can think of some naive algorithm creating every possible solution, and then searching through the solution space using DFS/BFS, but it will be highly nonoptimal.

Related

Finding closest combinations of a given sum without replacement [closed]

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 been dipping my feet into programming and originally was making a simple macro in VBA to find a certain combination that sum to a given number when given a list of inputs. I imagined a number of tasks and minutes to do those tasks, and inputted a number of people to divide the minutes approximately equal between them. To give a concrete example, if I had eight tasks and three people, I might have the following variables:
M = [44,39,29,77,102,35,40,59]
N = 3
Avg = sum(M)/N
I want the program to be able to find the set of combinations for each person that sum closest to the average value. For instance in this example, I would like an output of something like:
A = [102, 40], B = [44,39,59], C = [29,77,35]
If anyone can at least lead me in the right direction with regards to this project, I would be grateful. While this began as an aside from a macro for an Excel sheet, I wouldn't mind if I learned more about optimization algorithms in a more suitable language like Python.
Getting each persons work as close as possible to the mean is equivalent to max-min fair allocation problem
It’s essentially an optimization problem — google research did some work on this here
https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/45386.pdf
A CS professor wrote a Python module for this https://github.com/anirudhSK/cell-codel/blob/master/schism/utils/max-min-fairness.py

To optimize 20 parameters which should be the best algorithm to use? [closed]

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 2 years ago.
Improve this question
I have 20 parameters that can take binary value which are passed to function to return the score like this.
score = fmin( para 1, para 2 , para 3,.....para20)
Now to optimize this scenario, which can be the best algorithm ?
I read about genetic algorithm where in chromosome can do mutation and crossover to select best combination out of 2^20 search points.
I also read about hyperopt that optimises the function but in less number of trials.
Which can be the better one ? Any pros or cons of using these algorithms ?
It really depends on the properties you expect your function to have. If you have reason to believe that similar parameter sets have similar scores, then you can try simulated annealing or genetic algorithms.
However, if you don't have reason to expect similar parameters will generate similar scores, those methods won't help: you would do just as well picking parameter sets at random. But (as mentioned in the comments), 2^20 isn't much more than a million trials: if your function isn't too expensive, you could just try them all.

Text clustering/NLP [closed]

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
Imagine there is a column in dataset representing university. We need to classify the values, i.e. number of groups after classification should be as equal as possible to real number of universities. The problem is that there might be different naming for the same university. An example: University of Stanford = Stanford University = Uni of Stanford. Is there any certain NLP method/function/solution in Python 3?
Let's consider both cases: data might be tagged as well as untagged.
Thanks in advance.
A very simple unsupervised approach would be to use a k-means based approach. The advantage here is that you know exactly how many clusters (k) you expect, since you know the number of universities in advance.
Then you could use a package such as scikit-learn to create your feature vectors (most likely n-grams of characters using a Countvectorizer with the option analyzer=char) and you can use the clustering to group together similarly written universities.
There is no guarantee that the groups will match perfectly, but I think that it should work quite well, as long as the different spellings are somewhat similar.

How can I find a good distracter for a key using python [closed]

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 6 years ago.
Improve this question
What I am trying to do is to create a Multiple Choice Question (MCQ) generation to our fill in the gap style question generator. I need to generate distracters (Wrong answers) from the Key (correct answer). The MCQ is generated from educational texts that users input. We're trying to tackle this through combining Contextual similarity, similarity of the sentences in which the keys and the distractors occur in and Difference in term frequencies Any help? I was thinking of using big data datasets to generate related distractors such as the ones provided by google vision, I have no clue how to achieve this in python.
This question is way too broad to be answered, though I would do my best to give you some pointers.
If you have a closed set of potential distractors, I would use word/phrase embedding to find the closest distractor to the right answer.
Gensim's word2vec is a good starting point in python
If you want your distractors to follow a template, for example replace a certain word from the right answer with its opposite, I would use nltk's wordnet implementation to find antonyns / synonyms.

Quadratic Formula without import math [closed]

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 6 years ago.
Improve this question
Can somebody help me write a code using python 3 that can solve the quadratic formula without using "import math"? Please !
As #Aurora001 mentioned, you should not ask for completed code. However, I think addressing the method you might use could be a good answer to your question, and I hope others agree. This is how I would approach the problem:
Prompt for input to get the coefficients a, b, and c.
Write a method that finds the square root of a number (several algorithms exist and can be found with a Google search) - There are also more built-in ways to do exponentiation in Python without the math module but this seems like it is for a class and the point may be to see if you can write a sqrt implementation.
Write a method that uses your custom square root implementation to solve the quadratic equation using the coefficients as parameters.
Test your two methods by doing a few test cases.
I hope this helps; post another question if you have more specific issues. I have noticed more people will be willing to assist if you generate your own code and ask about specific problems that you cannot solve.

Categories

Resources