org.opt4j.satdecoding
Class AbstractSATDecoder<G extends org.opt4j.core.Genotype,P>

java.lang.Object
  extended by org.opt4j.satdecoding.AbstractSATDecoder<G,P>
Type Parameters:
G - The genotype (use Genotype if you do not override the decode method)
P - The phenotype
All Implemented Interfaces:
org.opt4j.core.problem.Creator<G>, org.opt4j.core.problem.Decoder<G,P>

public abstract class AbstractSATDecoder<G extends org.opt4j.core.Genotype,P>
extends java.lang.Object
implements org.opt4j.core.problem.Decoder<G,P>, org.opt4j.core.problem.Creator<G>

The AbstractSATDecoder can be used for the construction of custom SAT Decoders.

The Creator part takes the problem dependent Constraints and creates a SATGenotype according to the variables which is the input for the specified Optimizer.

The Decoder takes a SATGenotype, converts it to an Order of the variables, and solves the problem in the Order using a SAT Solver . The resulting Model, which respects the Constraints, must then be converted to the problem specific phenotype.


Field Summary
protected  boolean isInit
           
protected  java.util.Map<java.lang.Object,java.lang.Double> lowerBounds
           
protected  SATManager manager
           
protected  java.util.Random random
           
protected  java.util.Map<java.lang.Object,java.lang.Double> upperBounds
           
 
Constructor Summary
AbstractSATDecoder(SATManager manager, org.opt4j.core.common.random.Rand random)
          Constructs an AbstractSATDecoder with the given SATManager.
 
Method Summary
abstract  P convertModel(Model model)
          Converts a Model into a phenotype.
 G create()
           
abstract  java.util.Set<Constraint> createConstraints()
          Creates all Constraints.
protected  org.opt4j.core.Genotype createSATGenotype()
          Returns a random SAT genotype of the constrained problem.
 P decode(G genotype)
           
protected  Model decodeSATGenotype(org.opt4j.core.Genotype genotype)
          Decodes the Genotype to a phenotype by using a SAT/PB solver.
 java.util.List<Constraint> getConstraints()
          Returns the constraints.
 java.util.Map<java.lang.Object,java.lang.Double> getLowerBounds(java.util.Set<java.lang.Object> variables)
          Returns the lower bounds for the variables.
 java.util.Map<java.lang.Object,java.lang.Double> getUpperBounds(java.util.Set<java.lang.Object> variables)
          Returns the upper bounds for the variables.
 java.util.List<java.lang.Object> getVariables()
          Returns the variables.
 java.util.Set<java.lang.Object> ignoreVariables(java.util.Set<java.lang.Object> variables)
          Set the variables to be ignored (not part of the search process and genotype).
protected  void init()
          Initializes the Constraints and variables.
 void randomize(java.util.Collection<java.lang.Object> variables, java.util.Map<java.lang.Object,java.lang.Double> lowerBounds, java.util.Map<java.lang.Object,java.lang.Double> upperBounds, java.util.Map<java.lang.Object,java.lang.Double> priorities, java.util.Map<java.lang.Object,java.lang.Boolean> phases)
          Creates a random initialization of the priorities and phases for the variables.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lowerBounds

protected java.util.Map<java.lang.Object,java.lang.Double> lowerBounds

upperBounds

protected java.util.Map<java.lang.Object,java.lang.Double> upperBounds

random

protected final java.util.Random random

manager

protected final SATManager manager

isInit

protected boolean isInit
Constructor Detail

AbstractSATDecoder

@Inject
public AbstractSATDecoder(SATManager manager,
                                 org.opt4j.core.common.random.Rand random)
Constructs an AbstractSATDecoder with the given SATManager.

Parameters:
manager - the specified sat manager
random - the random number generator
Method Detail

init

protected void init()
Initializes the Constraints and variables.


createConstraints

public abstract java.util.Set<Constraint> createConstraints()
Creates all Constraints.

Override this method to return the problem specific Constraints that have to be respected by the resulting Model.

Returns:
the set of all constraints of the given problem

randomize

public void randomize(java.util.Collection<java.lang.Object> variables,
                      java.util.Map<java.lang.Object,java.lang.Double> lowerBounds,
                      java.util.Map<java.lang.Object,java.lang.Double> upperBounds,
                      java.util.Map<java.lang.Object,java.lang.Double> priorities,
                      java.util.Map<java.lang.Object,java.lang.Boolean> phases)
Creates a random initialization of the priorities and phases for the variables. Override this method for a custom initialization.

Parameters:
variables - all variables
lowerBounds - the lower bounds for the priority for the variables
upperBounds - the upper bounds for the priority for the variables
priorities - the priorities of the variables
phases - the phases of the variables

ignoreVariables

public java.util.Set<java.lang.Object> ignoreVariables(java.util.Set<java.lang.Object> variables)
Set the variables to be ignored (not part of the search process and genotype). Override this method if variables are ignored.

Parameters:
variables - all variables of the problem
Returns:
the variables to be ignored

getLowerBounds

public java.util.Map<java.lang.Object,java.lang.Double> getLowerBounds(java.util.Set<java.lang.Object> variables)
Returns the lower bounds for the variables.

Parameters:
variables - all variables of the problem
Returns:
the lower bounds

getUpperBounds

public java.util.Map<java.lang.Object,java.lang.Double> getUpperBounds(java.util.Set<java.lang.Object> variables)
Returns the upper bounds for the variables.

Parameters:
variables - all variables of the problem
Returns:
the upper bounds

convertModel

public abstract P convertModel(Model model)
Converts a Model into a phenotype. Override this with your custom method.

Parameters:
model - the found model
Returns:
the converted phenotype

create

public G create()
Specified by:
create in interface org.opt4j.core.problem.Creator<G extends org.opt4j.core.Genotype>

createSATGenotype

protected org.opt4j.core.Genotype createSATGenotype()
Returns a random SAT genotype of the constrained problem.

Returns:
a random SAT genotype

decode

public P decode(G genotype)
Specified by:
decode in interface org.opt4j.core.problem.Decoder<G extends org.opt4j.core.Genotype,P>

decodeSATGenotype

protected Model decodeSATGenotype(org.opt4j.core.Genotype genotype)
Decodes the Genotype to a phenotype by using a SAT/PB solver.

Parameters:
genotype - the genotype
Returns:
the phenotype

getConstraints

public java.util.List<Constraint> getConstraints()
Returns the constraints.

Returns:
the constraints

getVariables

public java.util.List<java.lang.Object> getVariables()
Returns the variables.

Returns:
the variables