All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.exigen.ie.constrainer.impl.ConstraintAllDiff2 Maven / Gradle / Ivy

package com.exigen.ie.constrainer.impl;
import com.exigen.ie.constrainer.Constrainer;
import com.exigen.ie.constrainer.Constraint;
import com.exigen.ie.constrainer.ConstraintImpl;
import com.exigen.ie.constrainer.EventOfInterest;
import com.exigen.ie.constrainer.Failure;
import com.exigen.ie.constrainer.Goal;
import com.exigen.ie.constrainer.GoalAnd;
import com.exigen.ie.constrainer.GoalGenerate;
import com.exigen.ie.constrainer.GoalPrint;
import com.exigen.ie.constrainer.GoalPrintObject;
import com.exigen.ie.constrainer.IntExp;
import com.exigen.ie.constrainer.IntExpArray;
import com.exigen.ie.constrainer.IntValueSelector;
import com.exigen.ie.constrainer.IntValueSelectorMin;
import com.exigen.ie.constrainer.IntVar;
import com.exigen.ie.constrainer.IntVarSelector;
import com.exigen.ie.constrainer.IntVarSelectorMinSize;
import com.exigen.ie.constrainer.Observer;
import com.exigen.ie.constrainer.Subject;

///////////////////////////////////////////////////////////////////////////////
/*
 * Copyright Exigen Group 1998, 1999, 2000
 * 320 Amboy Ave., Metuchen, NJ, 08840, USA, www.exigengroup.com
 *
 * The copyright to the computer program(s) herein
 * is the property of Exigen Group, USA. All rights reserved.
 * The program(s) may be used and/or copied only with
 * the written permission of Exigen Group
 * or in accordance with the terms and conditions
 * stipulated in the agreement/contract under which
 * the program(s) have been supplied.
 */
///////////////////////////////////////////////////////////////////////////////

/**
 * An implementation of the constraint "All Different".
 *
 * Any two constrained integer expressions from the vector (parameter of this
 * constraint) should can not be instantiated with the same value.
 */
public final class ConstraintAllDiff2 extends ConstraintImpl
{
  // PRIVATE MEMBERS
  private IntExpArray	     _intvars;
  private IntVar _bit_var; // one bit for every possible values among all _intvars

  //////////////////////////////////////////////// inner class AllDiffObserver
  class AllDiffObserver extends Observer
  {
    public void update(Subject var, EventOfInterest interest)
        throws Failure
    {
      IntExp event_var = (IntExp)var;
      //Debug.on(); Debug.print("AllDiffObserver("+var+") "+interest+" "+_bits); Debug.off();
      int value = event_var.value();
      // check for failure
      if (!_bit_var.contains(value))
      {
        //Debug.on();Debug.print("diff fail: "+interest+_intvars+_bits);Debug.off();
        var.constrainer().fail("AllDiff"); //+_bits +" "+_intvars);
      }

      // set the bit
      int size = _intvars.size();
      _bit_var.removeValue(value);  //Debug.on();Debug.print(" "+this+":  "+_bits);Debug.off();

      // additional propagation
      for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy