[gecode-users] Help with count method in script

George Rudolph george.rudolph at citadel.edu
Thu Sep 20 16:58:27 CEST 2007


I would like help with the following Gecode/J script.
As indicated below, when I uncomment the calls to count
and run the script, it fails--but I am expecting two results.
What am I doing incorrectly?
(Note: For those it may interest, I am using Gecode/J with Eclipse.)

--------- begin code -----------

package citadel;

import static org.gecode.Gecode.*;
import static org.gecode.GecodeEnumConstants.*;

import org.gecode.*;

/**
*   Script for computing 2-class association schemes,
*   modified from the Queens example, and uses the example.Options class
*   unchanged.
*   The goal of this script is to generate (v-1)-length sequences
*   with the following properties:
*   1. v is prime and v=4t+1, t >=0.
*   2. each sequence has n1 occurrences of lambda1 and n2 occurrences of
lambda2.
*   3. the sequence is a palindrome:
*      element 0 and element v-2 have the same value,
*      element 1 and element v-3 have the same value,
*      element 2 and element 4-4 have the same value, 
*      etc.
*   
*   @author George Rudolph
*   @version 1.0 Sep 20, 2007
*/
public class AssociationScheme extends Space {
  public int v;
  public int n1;
  public int n2;
  public int lambda1;
  public int lambda2;
  public VarArray<IntVar> schemeCount;

  /**
 * @param opt Convenience object containing options 
 * @see citadel.Options#toString()
 */
public AssociationScheme(Options opt) {
    super();
    v = opt.size;
    n1= (v-1)/2;
    n2 = (v-1)/2;
    lambda1 = 1;
    lambda2 = 2;
    schemeCount = new VarArray<IntVar>(this, v-1, IntVar.class, 1, 2);
       
    //in the difference vector, constrain it so that
    //the value of position i is the same as the value at position v-i
    //for a (v-1)-length array starting at (conceptual) index 1
    //TODO: simplify the indexing in this constraint
    for (int i=1; i<=v-1; i++)
    {
      rel(this, schemeCount.get(i-1), IRT_EQ, schemeCount.get(v-1-i),
opt.icl);
    }
    /** need help with these -- when I uncomment these constraints 
     * and run, I get a failed space, but I am expecting two results:
     * [1,2,2,1] and [2,1,1,2]
     * What have I done incorrectly?
     */
    //n1 slots have the value lambda1, n2 slots have the value lambda2
    // what I want to say is "exactly n1 elements have the value lambda1
in q"
    // for example.
    //count(this, q, n1, IRT_EQ, lambda1, opt.icl );
    //count(this, q, n2, IRT_EQ, lambda2, opt.icl );
    
    branch(this, schemeCount, BVAR_SIZE_MIN, BVAL_MIN);
  }

  /**
   * Copy constructor.
 * @param share
 * @param scheme
 */
public AssociationScheme(Boolean share, AssociationScheme scheme) {
    super(share, scheme);
    v = scheme.v;
    n1= (v-1)/2;
    n2 = (v-1)/2;
    lambda1 = 1;
    lambda2 = 2;
    schemeCount = new VarArray<IntVar>(this, share, scheme.schemeCount);
  }

  /**
 *
 * @see org.gecode.Space#toString()
 */
public String toString() {
    
    return schemeCount.toString();
  }

  /**
   * Application startup
 * @param args
 */
public static void main(String[] args) {
    Options opt = new Options();
    opt.size = 5;
    opt.gui = true;
    opt.parse(args);
    opt.name = "" + opt.size + "-Schemes";

    AssociationScheme schemes = new AssociationScheme(opt);
    opt.doSearch(schemes);
  }
}
--------- end code   -----------

--------------------
George Rudolph
Assistant Professor
Thompson Hall 225
Math & Computer Science Dept.
The Citadel
171 Moultrie St.
Charleston, SC 29409




More information about the gecode-users mailing list