How to find all possible solutions with backtracking search? - artificial-intelligence

I want to solve a problem very similar to graph-coloring with the backtracking search, but I want to get "all" of the solutions to the problem and not just one possible solution.
How should I change the below algorithm that is stated in the book "Artificial Intelligence, the modern approach" to get all the solutions? ( assume that the number of nodes(variables) is not a lot (for example n<100) so that we can have all the solutions.)

Related

Clingo: Intersecting All Possible Optimal Solutions (ASP)

I want to find atoms, within a pre-defined set of atoms, that are in all possible optimal solutions of an ASP problem.
I'll explain what i want to do. I have an optimization problem where multiple optimal answer sets can exist. An answer set consists of atoms that characterizes a solution, for example node(0), edge(1,2) , as well as some that are not relevant, like color(0).
I want to compute all optimal answer sets, only show atoms of the type node() and edge(), then find the specific relevant atoms (like node(0) and edge(1,0)) that exist in all optimal answer sets.
I know i can limit the output of certain atoms with the #show directive. I can also add the flags --opt-mode=optN to compute all optimal answer and limit the output to only those with --quiet=1.
As per guide, using --enum-mode cautious computes the intersection of all answer sets.
An example:
If i have two optimal answer sets:
Answer set 1: node(1) node(0) edge(1,0) edge(0,1) color(1)
Answer set 2: node(1) node(0) edge(1,0) color(0)
I want to the result node(1) node(0) edge(1,0)
I can run clingo with --opt-mode=optN --quiet=1 then manually search for all node() or edge() atoms that all answer sets have in common.
I can add #show node/1 #show edge/2 to my encoding then run clingo with --opt-mode=optN --quiet=1 --enum-mode cautious.
Are all those two options logically equivalent?
Is there a more efficient way of achieving what i want?
I'm unsure about the interplay between the #show directive and the --opt-mode, --quiet and --enum-mode flags. I have a problem where answer sets can be very large, so i would prefer using option 2 since it would use the least disk space.
Thank you in advance.
You are definitely on the right track. I'm unsure about the combination of options though, especially --quiet as it only prevents showing the non-optimal models, but they will still be counted as models for the --enum-mode=cautious thingy.
You should simply use the clingo python API to achieve your goal. First, compute one optimal solution. Then you do have the bound that you can give as an additional argument to the opt-mode and your approach should work.
https://potassco.org/clingo/python-api/current/clingo/

Genetic Algorithm for finding the best path for a bot

I have been recently coding on codingames.com. In that I came across few problem in which it seems we need to use genetic algorithm for finding the best path for my bot.
First I started up with basic if else statement algorithms, which was just fine to make me reach to the bronze league of the contest. But then this algorithm made me no good. I searched on net on how to go ahead, and most of the winners of the bot programming suggested that they used genetic algorithm for the purpose.
I searched on net about GA, and got to know that we start with a given population and then we do some crossover and mutation thing to find the fittest genes existing in the population.
But my question is that how to apply the logic in the bot designing where we have to decide the thrust given to the bot and the degree of turning for the bot.
Here is the link to the question - https://www.codingame.com/ide/puzzle/coders-strike-back
I would be really glad if someone could send me not just the genes description for this problem as its already available on - https://www.codingame.com/blog/one-hour-learn-bot-programming/
I know the genes or genome which I may use. I want to know that how can I use it to predict my path. Would be glad if someone shares a pseudo code of how the algorithm works in this question.
There is a -3 velocity formula that will get you to your goal:
print nextcheckpointx-3*velocity, cextcheckpointy-3*velocity, 'BOOST'

Find-S concept learning algorithm

I am implementing and analysing the Find-S Algorithm (which I understood quite well). However, for the testing part, I am not sure whether the order of the examples in the training set affect the output.
Is this known or still unproven?
The order of examples will not affect the output if the function which expands the hypothesis is associative -- that is, if f(f(h0),x1),x2) = f(f(h0,x2),x1) for all h0,x1,x2.
The order of instances will affect your output because when FIND-S try to maximally specific hypothesis, it looks attributes and their values. It is discussed in Tom Mitchell's Machine Learning Book under title of '2.4 FIND-S FINDING A MAXIMALLY SPECIFIC HYPOTHESIS'.

AI Algorithm - connecting given pairs of vertices of a Matrix shaped graph without conflicts

I am looking for AI algorithms to connect halls in a simple circuit, which I assumed that could be represented as a tow dimensional matrix which itself lead to a graph problem.
I cant find such algorithms, so I can add an heuristic to.
I am pretty sure that this is a famous AI problem but cant figure out its name,
Hopefully any body can tell me where to find such algorithms and assure me about that assumption of mine about the circuit and its representation as graph is true.
Thanks.
I'm not sure what you mean by "connect halls", but if you are trying to lay out a circuit, maybe searching for "topological planar routing algorithm " will help you in your search.
Also, the following article might give you ideas:
http://en.m.wikipedia.org/wiki/Routing_(electronic_design_automation)

how to find a path to go home - algorithm

(source: blogcu.com)
Assume there is a rabbit and at position (1,1). Moreover, its home is at position (7,7). How can it reach that position ?
Home positon is not fix place.
Real question, I am trying to solve a problem on a book for exersizing c.What algorithm should I apply to find solution?
Should I use linked list to store data?
Data is (1,1), (1,2),..., (3,3) ..., (7,7)
Place marked with black shows wall.
Use A*. It is the classic go-to algorithm for path-finding (that article lists many other algorithms you can consider too).
By using A* you learn an algorithm that you might actually need in your normal programming career later ;)
An example evaluation of a maze similar to that in the question using A*:
There are a bunch of search algorithms you can use. The easiest to implement will be either breadth-first search or depth-first search.
Algorithms like A* are likely to be more efficient but are a little harder to code.
Check out the Wikipedia "Search algorithms" page. It has links to a number of well-known algorithms.
Breadth-first search is always a good one.
http://www.codeproject.com/KB/recipes/mazesolver.aspx

Resources