org.chocosolver.solver.exception.ContradictionException Maven / Gradle / Ivy
/*
* This file is part of choco-solver, http://choco-solver.org/
*
* Copyright (c) 2022, IMT Atlantique. All rights reserved.
*
* Licensed under the BSD 4-clause license.
*
* See LICENSE file in the project root for full license information.
*/
package org.chocosolver.solver.exception;
import org.chocosolver.solver.Cause;
import org.chocosolver.solver.ICause;
import org.chocosolver.solver.variables.Variable;
/**
* A specific Exception
to deal with contradiction.
*
* A contradiction appears when at least one Variable
object is not coherent
* regarding all or part of Constraint
network.
* Empty domain, instantiation to an out-of-domain value, etc. throws contradiction.
*
* For performance consideration, a ContradictionException
is created every time a contradiction
* occurs. A unique object is build and set with specific case information.
*
* @author Xavier Lorca
* @author Charles Prud'homme
* @version 0.01, june 2010
* @since 0.01
*/
public final class ContradictionException extends Exception {
public ICause c;
public Variable v;
public String s;
public ContradictionException() {
// does not call super() on purpose
c = Cause.Null;
v = null;
s = null;
}
/**
* Throws the unique ContradictionException
filled with the specified parameters.
*
* @param c the constraint at the origin of the contradiction
* @param v the variable concerned by the contradiction
* @param s the message to print
* @return ContradictionException the filled exception
*/
public ContradictionException set(ICause c, Variable v, String s) {
assert c != null;
this.c = c;
this.v = v;
this.s = s;
return this;
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "CONTRADICTION (" + (c == null ? "" : c + ", ") + v + ") : " + s;
}
/**
* {@inheritDoc}
*/
@Override
public synchronized Throwable fillInStackTrace() {
return this;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy