org.chocosolver.memory.IEnvironment Maven / Gradle / Ivy
Show all versions of choco-solver Show documentation
/*
* This file is part of choco-solver, http://choco-solver.org/
*
* Copyright (c) 2023, 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.memory;
import org.chocosolver.memory.structure.BasicIndexedBipartiteSet;
import org.chocosolver.memory.structure.IOperation;
/**
* An interface to ease declaration of backtrackable objects (mostly primitives).
*
* @author Charles Prud'homme, Hadrien Cambazard, Guillaume Rochart
*/
public interface IEnvironment {
/**
* Returns the world number.
*
* @return current world index
*/
int getWorldIndex();
/**
* Starts a new branch in the search tree.
*/
void worldPush();
/**
* Backtracks to the previous choice point in the search tree.
*/
void worldPop();
/**
* Backtracks to the w
previous choice point in the tree search
*
* @param w world index to pop to
*/
void worldPopUntil(int w);
/**
* Comitting the current world: merging it with the previous one.
*
* Not used yet.
*/
void worldCommit();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Factory pattern: new IStateBool objects are created by the environment
*
* @param initialValue the initial value of the backtrackable boolean
* @return Boolean object created by the environment
*/
IStateBool makeBool(boolean initialValue);
/**
* Factory pattern: new IStateInt objects are created by the environment
* (no initial value is assigned to the backtrackable search)
*
* @return new IStateInt computed by the environment
*/
IStateInt makeInt();
/**
* Factory pattern: new IStateInt objects are created by the environment
*
* @param initialValue the initial value of the backtrackable integer
* @return new IStateInt computed by the environment
*/
IStateInt makeInt(int initialValue);
/**
* Factory pattern: new StoredFloat objects are created by the environment
* (no initial value is assigned to the backtrackable search)
* @return new IStateDouble computed by the environment
*/
@SuppressWarnings("unused")
IStateDouble makeFloat();
/**
* Factory pattern: new StoredFloat objects are created by the environment
*
* @param initialValue the initial value of the backtrackable search
* @return new IStateDouble computed by the environment
*/
IStateDouble makeFloat(double initialValue);
/**
* Factory pattern: new backtrackable long attached to this environment.
* @return a backtrackable long
*/
@SuppressWarnings("unused")
IStateLong makeLong();
/**
* Factory pattern: new backtrackable long attached to this environment.
* @param init its initial value
* @return a backtrackable long
*/
IStateLong makeLong(long init);
/**
* Factory pattern: new IStateBitSet objects are created by the environment
*
* @param size initial size of the IStateBitSet
* @return IStateBitSet
*/
IStateBitSet makeBitSet(int size);
/**
* Factory pattern: new SparseBitSet objects are created by the environment
*
* @param blocksize block size in bits.
* @return IStateBitSet
*/
IStateBitSet makeSparseBitset(int blocksize);
/**
* Factory pattern: new IStateIntVector objects are created by the environment
*
* @param size the number of entries in the vector
* @param initialValue the common initial value for all entries (backtrackable integers)
* @return a backtrackable vector
*/
IStateIntVector makeIntVector(int size, int initialValue);
/**
* Factory pattern: new IStateDoubleVector objects are created by the environment
*
* @param size the number of entries in the vector
* @param initialValue the common initial value for all entries (backtrackable integers)
* @return IStateDoubleVector
*/
IStateDoubleVector makeDoubleVector(int size, double initialValue);
/**
* Factory pattern : shared IndexedBipartiteSet object is return by the environment
*
* @return IndexedBipartiteSet
*/
@SuppressWarnings("unused")
BasicIndexedBipartiteSet getSharedBipartiteSetForBooleanVars();
/**
* Save this operation onto the stack of operations to undo on backtrack.
* @param operation operation to undo
*/
void save(IOperation operation);
/**
* Save this operation onto the stack of operations to undo on backtrack, at level `worldIndex`.
* @param operation operation to undo
* @param worldIndex when to apply this
*/
void saveAt(IOperation operation, int worldIndex);
/**
* Return the current time stamp.
* It differs from world index since it never decrements.
* @return the timestamp
*/
int getTimeStamp();
}