This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!

Antoine Compagnie

Ranch Hand
+ Follow
since Dec 01, 2015
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Antoine Compagnie

Hi there!

I want to code a forwardchecking algorithm in java...
I already have a parser class with a main that creates the variables, binary constraints, ...

I'm now coding the algorithm that deals with all that stuff and I'm stuck. I don't know how to assign variables and check the constraints before going further.

I'm tring to colour eahc state of Australia with one colour. No surrounding state of a given state should have the same colours.

here is the algorithm code :

And here is the class that creates  the variables, binary constraints, ...

Can you help me having a good start?

Here is a reminder of the algorithm :

2 years ago
From Ishmael, San Franciso:

f frontier is a Stack or something similar, than add is analogous to push, so your BFS is in fact also doing a depth-first search. If you actually want to insert at the beginning (something you want to do if you pop elements on each iteration), you want to call .add(0, elem) (note the 0 -- the index at which to insert) instead of .add(elem), so that it is actually inserted at the beginning.

I think he find it out.
2 years ago
I'm trying to build up a program comparing number of strokes of  algorithms BFS, DFS, A* (which has two heuristics) on a game of fifteen.

My counter count the same result for the two arrays of counters of BFS and DFS and both A*. Yet, I'm using actually using four different arrays from a main (class Project) and I'm assigning four different variables for those strokes.

The part of the code that isn't right is, to my mind, a while loop which explores the son of a vertice as far as possible (for BFS) or discovering each following nodes (for BFS). The difference, which is of the utmost importance, is the last line of code which is either frontier.push(child);, for DFS, or frontier.add(child); for BFS.

Each time we enter the loop, the number of strokes is incremented  


When we find the final state we add the result to the array of the number of strokes:


Here is the actual problem as far as when I let array_number_of_strokes_dfs.add(number_of_strokes_DFS);, for instance, I always get the same result as BFS in the array. It might happen once, but not every time!!!
Whereas if I add a zero

I do see the difference...

Do you have any ideas?
2 years ago
I have a serious problem.
I am a serious issue. Having the time that took each algorithm for each problem I am able to calculate the mean of the BFS algorithm but any one of the other ones:
Here is the code to diplay the result and calculate the means:

Here is the result.txt file content:

And here is the mean.txt file

2 years ago
I have a serious problem.
I am a serious issue. Having the time that took each algorithm for each problem I am able to calculate the mean of the BFS algorithm but any one of the other ones:
Here is the code to diplay the result and calculate the means:

[code=java PrintWriter writer = new PrintWriter("result.txt", "UTF-8");
writer.println("runTime DFS" + runTimesDFS);
writer.println("run time BFS : " + runTimesBFS);
writer.println("run Times AStar1" + runTimesAStar1);
writer.println("run Times AStar2" + runTimesAStar2);



PrintWriter writer1 = new PrintWriter("mean.txt", "UTF-8");

for(int i =0;i<problemSize;i++){


Here is the result.txt file content:

2 years ago
Indeed, I was maybe too much enthusistic of creating my first GUI. I do have a good A* algorithm but I'm not able to catch good statistics.

I want to catch the mean of the time that took each algorithm on problems that were to be solved in specific times: % 2 has to be solved in two movments, % 3 in three movments. At the moment I am able to catch these times for every algorithm that hasn't failed to solve a given problem in less than a second.
Yet, how to deal with algorithms that take too much time? How to calculate the mean?
2 years ago
I actually had some problem solving some puzzles so I started a timer for each algorithm when lunched which stop the algorithm after a second.
I now have the results in time but I'm not able to display them properly on the JFrame. It writes the result at the same place in the middle each time it solve a problem with an algorithm.
2 years ago
Hi everyone!

I am trying to code A* algorithm along with Breadth First Search and Depth First Search on several game of fifteen (reduced to 3*3 games) problem stored in a file games.txt from which I show an exerpt:

% 2
% 4
% 5

I want to be able to display a following array:

Yet I am not able to display the result of the algorithms in the JFrame. On the one hand I am not able to iterate, on the other hand, I am not able to stop algorithm that would take too much time such as DFS.
Can you help me displaying the results in time in my JFrame each time an algorithm has solved or fill a blank if it took too much time?

My code (javaproject) is composed of several files:

  • [*]Problem

  • A Puzzle implements Searchable.

    The main is contained in Project. It contains the graphic components:
    Two classes display the result :
  • [*]Window

  • Ask me for anymore details !

    Here are the two important files to modify:


    And here is the code of Project with the main:

    2 years ago
    Dear all,

    this is almost done. Thanks for all your support and help. I have to finish it for Tuesday then it will be done. I'm able to deal with the following files apart from the love/hate relationship:

    A way to know which stores are located in which cities:

    Yet, I'm not able to deal with the "cut/!", which makes a Clause readable only once.

    But that's not the most important. The most important is that I have yet to deal with the predicate :- which precise what a clause is made of.
    It seems from SWISH that even if the goal has the same litteral than the first clause it has firs to unify with the one with ":-"
    I tried during hours to make it work the right way but still
    My last will here on this topic is your help to revert this loop, to make it clear for the program to start with :- clause:

    For example let's take the multiplication of 2 by 3

    if unifying with the first clause it would give write(R) has an output with nothing in it.
    The second case would give 6, the actual result of the multiplication of 2 by 3.

    I'm going to give you my code but in order to change the step by step method to the classic display method, two variables have to be modified: display and caseDisplay which are boolean

    The first one shows how does the resolution is being processed clause by clause.
    The second one shows how does cases are managed.

    The for loop I am talking about is the following one:

    IR is the Resolution indice, the goal is copieResolvante, courante is each clause we are testing (and we want to test the from the bottom to the top).

    Here is the whole code, the file has to be placed in with the name you will give him instead of and placed at the root of the workspace.

    Enough speaking. If you're willing to help me and I would be very grateful!!!

    Two other files are associated: the class Couples...

    And the class Symbol

    I still have to create a manager GUI interface in order to make this thing user friendly.
    2 years ago
    Thank you for still consideing my issues then!

    I will try to use your advises to improve his code.

    His code doesn't do all the work. He left some things in order to let us work on it such as the var var case const/const or the rules...

  • write is used to write the given clause

  • nl print a new line

  • We will have for instance

    Which means Shop Youpi! located in Paris.

  • rules ar special cases when there is variables in a clause which is not the goal

  • Here it means that everybody loves mia and vincent loves everybody.

    All of this has to be written out when unification is done, that is to say when boolean unif(Clause c) is called.
    2 years ago
    I know... :'(

    But... I have to use it anyway. Mine does the work but isn't really cleaner!

    I added in his code

    and received:

    I'm quite depressed letting my code for his own... But I think this is common in the industry...I will make it!
    2 years ago
    Okay, here it is, the first version to work:

    Alas! it only work for simple resolution questions. It semms not to be okay for more complex programs such as

  • write,nl
  • rules

  • This file with the question asked on the last line, I mean if vincent is jealous of Marcellus, would work.

    Whereas this one: wouldn't as far as there are now new thing to apply such as write and new line.

    Furthermore, my teacher told me my code would not gives right answers if I had to apply it on example such as:

    In the first example they are not used. They mean everybody loves mia and vincent loves everybody.

    No need to wait more, I'm giving you this code and the one my teacher gived me if I wasn't able to cope with this two new challenges.

    Therefore the following one is from my teacher, one as to notice that he used array for ListeClauses rather than LinkedList.
    It allows him to do something I can't that is to say to add his new resolution clause furhter down and to navigate better between, step by step when they can't be unified.

    2 years ago
    You were right!

    I just stop coding for a day did some tests on some Prolog examples.

    The loop was awful, I did it again
    after testing my code bit by bit I noticed that the error was that i didn't did all what was needed to to do the unifcation.
    The constant vs variable part was missing the Symbol diplaying modifications after unifying:

    Now, it's almost done. All I have to do is to loop over the loop with a while until the goal can't be unified anymore with any clauses.
    To do that I will have to add a goal each time I unify and exit the inner loop to iterate again over the clauses.

    I liked you joke on Jean-Paul!
    I will post my code when I think it will be ready enough for facing your judgments. Actually my main has only 40 lines of really used code! The rest is ruins of avorted ideas that can still help me!
    2 years ago
    First :ir Resolution Indice: is where the goal is. It will increase as far as we are creating new goals through resolutions.

    Next, I loop over every line but the last one, that's okay as far as we are first looking for the first possible clause to unify with the goal.

    Next you set 'goal' to the element before the last one.

    Should I do

    to set is as the goal?

    plainly isn't going to work if ListClauses has less than two elements in it - which is definitely the case here.

    Okay, listClause have to have two elements. Else remove(0) will leave and empty collection.
    Yet, why was it working during the by hand method? Actually when I have

    I have to have after unif, remove andall:

    Here is what I did with the byhand method.

    And if I do

    I get:

    Which is almost what I want, it lacks Y transformation.
    2 years ago
    Of course for the error code:!

    And sorry for long lines, I just did a Ctrl+I and will try to short my lines in the future.

    here it is
    3 years ago