[gecode-users] Simpler examples?

Mikael Zayenz Lagerkvist zayenz at gmail.com
Tue Mar 18 07:13:11 CET 2008


I general, I think that all the examples should use the Options.java
file, since we want all examples to behave the same. Given that, some
explanation in the introduction page could be added to explain what is
done in the Options file. By cutting out all the parts of
Options.doSearch() that are not used for the queens-example, we get
the following code (with some added comments and reformatting):

  // Modified from Options.doSearch()
  public void doSearch(Space g, Stop stop) {
    // Options class for the search-engine
    org.gecode.Options o = new org.gecode.Options();
    o.setA_d(a_d); o.setC_d(c_d); o.setStop(stop);
    // Statistics from the search
    Statistics stat = null;
    // Number of solutions to search for
    long nsols = solutions;
    // Time the search is started
    long startTime = System.nanoTime();
    // Final time
    long time;
    // Construction of search-engine iterator
    DFSIterator<Space> search = new DFSIterator<Space>(g,o);
    // Iterate over all the solutions, until enough has been found
    for (Space sol : search) {
      if (print)
	System.out.println(sol.toString());
      if (--nsols == 0) break;
    }
    // Get and print all relevant statistics
    stat = search.statistics();
    time = System.nanoTime() - startTime;
    System.out.println("Summary:" +
		       "\n\truntime:      " + (time/1000000) +
		       "\n\tsolutions:    " + (solutions-nsols));
    if (stat != null) {
      System.out.println("  \tpropagations: " + stat.getPropagate() +
			 "\n\tfailures:     " + stat.getFail() +
			 "\n\tclones:       " + stat.getClone() +
			 "\n\tcommits:      " + stat.getCommit() +
			 "\n\tpeak memory:  " +
			 ((stat.getMemory()+1023)/1024) + "KB");
    }
  }


Hope this helps,
Mikael

On Tue, Mar 18, 2008 at 6:15 AM, Malcolm Ryan <malcolmr at cse.unsw.edu.au> wrote:
> Oh, I understand the Queens.java file, but much of the search
>  behaviour is hidden inside Options.java, which is harder to follow. I
>  was hoping you could explain some of that code as well.
>
>  Malcolm
>
>
>
>  On 18/03/2008, at 2:28 PM, Christian Schulte wrote:
>
>  > Did you check this one:
>  >
>  > http://www.gecode.org/gecodej/doc/PageIntro.html
>  >
>  > Christian
>  >
>  > --
>  > Christian Schulte, www.ict.kth.se/~cschulte/
>  >
>  >
>  > -----Original Message-----
>  > From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On
>  > Behalf
>  > Of Malcolm Ryan
>  > Sent: Tuesday, March 18, 2008 4:19 AM
>  > To: gecode list
>  > Subject: [gecode-users] Simpler examples?
>  >
>  > Hi,
>  >
>  > May I ask that you add some simpler examples to the GecodeJ
>  > distribution, which do not use the Options class included? By being
>  > able to handle all manner of different search types, the class loses
>  > its value as an example. It is hard to follow and difficult to see
>  > which bits are necessary and which bits are not. A bare-bones example
>  > would be useful. What is the minimum amount you need to create a
>  > problem and then solve it?
>  >
>  > Thanks,
>  >
>  > Malcolm
>  >
>  >
>  > _______________________________________________
>  > Gecode users mailing list
>  > users at gecode.org
>  > https://www.gecode.org/mailman/listinfo/gecode-users
>
>
>  _______________________________________________
>  Gecode users mailing list
>  users at gecode.org
>  https://www.gecode.org/mailman/listinfo/gecode-users
>



-- 
Mikael Zayenz Lagerkvist, http://www.ict.kth.se/~zayenz/




More information about the gecode-users mailing list