Package javax.constraints.impl.constraint

Source Code of javax.constraints.impl.constraint.Cardinality

//================================================================
// J A V A  C O M M U N I T Y  P R O C E S S
//
// J S R  3 3 1
//
// CONSTRAINER-BASED REFERENCE IMPLEMENTATION
//
// Copyright (c) Cork Constraint Computation Centre, 2010
// University College Cork, Cork, Ireland, www.4c.ucc.ie
// Constrainer is copyrighted by Exigen Group, USA.
//
//================================================================
package javax.constraints.impl.constraint;


import javax.constraints.Var;
import javax.constraints.impl.Constraint;
import javax.constraints.impl.Problem;

import com.exigen.ie.constrainer.Constrainer;
import com.exigen.ie.constrainer.IntExp;
import com.exigen.ie.constrainer.IntExpArray;

/**
* This constraint defines a new constrained integer variable "cardinality"
* that is equal to the number of elements of the
* array of variables "vars" which are bound to the "value" or "var" .
*
*/

public class Cardinality extends Constraint {
 
  static final String name = "Cardinality";
 
  /**
   * Example: cardinality(vars,cardValue) < var
   */
  public Cardinality(Var[] vars, int cardValue, String oper, Var var) {
    super(vars[0].getProblem(),name);
    Problem problem = (Problem) vars[0].getProblem();
    Constrainer constrainer = problem.getConstrainer();
    IntExpArray cVars = problem.getExpArray(vars);
    try {
      IntExp cardinality = constrainer.cardinality(cVars,cardValue);
      problem.defineConstraintImpl(this, cardinality, oper, var);
    } catch (Exception f) {
      throw new RuntimeException(
          "Failure to create constraint "+name);
    }
  }
 
  /**
   * Example: cardinality(vars,cardVar) < var
   */
  public Cardinality(Var[] vars, Var cardVar, String oper, Var var) {
    super(vars[0].getProblem(),name);
    Problem problem = (Problem) vars[0].getProblem();
    Constrainer constrainer = problem.getConstrainer();
    IntExpArray cVars = problem.getExpArray(vars);
    try {
      IntExp cVar = (IntExp) cardVar.getImpl();
      IntExp cardinality = constrainer.cardinality(cVars,cVar);
      problem.defineConstraintImpl(this, cardinality, oper, var);
    } catch (Exception f) {
      throw new RuntimeException(
          "Failure to create constraint "+name);
    }
  }
 
  /**
   * Example: cardinality(vars,cardValue) < value
   */
  public Cardinality(Var[] vars, int cardValue, String oper, int value) {
    super(vars[0].getProblem(),name);
    Problem problem = (Problem) vars[0].getProblem();
    Constrainer constrainer = problem.getConstrainer();
    IntExpArray cVars = problem.getExpArray(vars);
    try {
      IntExp cardinality = constrainer.cardinality(cVars,cardValue);
      problem.defineConstraintImpl(this, cardinality, oper, value);
    } catch (Exception f) {
      throw new RuntimeException(
          "Failure to create constraint "+name);
    }
  }
 
  /**
   * Example: cardinality(vars,cardVar) < value
   */
  public Cardinality(Var[] vars, Var cardVar, String oper, int value) {
    super(vars[0].getProblem(),name);
    Problem problem = (Problem) vars[0].getProblem();
    Constrainer constrainer = problem.getConstrainer();
    IntExpArray cVars = problem.getExpArray(vars);
    try {
      IntExp cVar = (IntExp) cardVar.getImpl();
      IntExp cardinality = constrainer.cardinality(cVars,cVar);
      problem.defineConstraintImpl(this, cardinality, oper, value);
    } catch (Exception f) {
      throw new RuntimeException(
          "Failure to create constraint "+name);
    }
  }
   
}
TOP

Related Classes of javax.constraints.impl.constraint.Cardinality

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.