Class CombinatoricsProblem
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
java.util.HashSet<OptProbElement>
org.tweetyproject.math.opt.problem.GeneralConstraintSatisfactionProblem
org.tweetyproject.math.opt.problem.CombinatoricsProblem
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<OptProbElement>,Collection<OptProbElement>,Set<OptProbElement>
- Direct Known Subclasses:
KnapSack,TravelingSalesman
This class implements a combinatorial optimization problem
- Author:
- Sebastian Franke
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionelementsstatic final intStatic constant for the type "maximization"static final intStatic constant for the type "minimization" -
Constructor Summary
ConstructorsConstructorDescriptionCombinatoricsProblem(List<ElementOfCombinatoricsProb> elements, int[][] graphRepresantation) constructor -
Method Summary
Modifier and TypeMethodDescriptionabstract ArrayList<ElementOfCombinatoricsProb>create a solution that changes the solution currSol a little bit (i.e.: for TSP: swap 2 cities; for KnapSack: add a random element) for currSol == null: create a random solutionabstract doubleevaluates the solutionformNeighborhood(ArrayList<ElementOfCombinatoricsProb> currSol, int minIterations, int maxIteration, double threshold) int[][]abstract DoublegetHeuristicValue(ElementOfCombinatoricsProb solutionComponent, Integer getCurrentIndex, ElementOfCombinatoricsProb initialReference, ElementOfCombinatoricsProb[] sol) for Ant optimization: give a chance between 0 and 1 for accepting solutionComponent to the solution solabstract double[][]for Ant optimization: represent the problem as an adjacence matrixabstract booleanchecks if a given solution is valid under all constraintsabstract doubleMethods inherited from class java.util.HashSet
add, clear, clone, contains, isEmpty, iterator, remove, size, spliterator, toArray, toArrayMethods inherited from class java.util.AbstractSet
equals, hashCode, removeAllMethods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toStringMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Field Details
-
MINIMIZE
public static final int MINIMIZEStatic constant for the type "minimization"- See Also:
-
MAXIMIZE
public static final int MAXIMIZEStatic constant for the type "maximization"- See Also:
-
elements
elements
-
-
Constructor Details
-
CombinatoricsProblem
constructor- Parameters:
elements- elementsgraphRepresantation- problem
-
-
Method Details
-
createDifference
public ArrayList<ElementOfCombinatoricsProb> createDifference(ArrayList<ElementOfCombinatoricsProb> c) - Parameters:
c- the List to be subtracted from "this" List- Returns:
- the differnece of the lists
-
sumOfWeights
- Parameters:
sol- is the solution to be viewd- Returns:
- if the solution sol is valid under the constraints of the problem
-
formNeighborhood
public ArrayList<ArrayList<ElementOfCombinatoricsProb>> formNeighborhood(ArrayList<ElementOfCombinatoricsProb> currSol, int minIterations, int maxIteration, double threshold) - Parameters:
currSol- current solutionminIterations- minimum iterationsmaxIteration- maximum iterationsthreshold- threshold- Returns:
- neighborhood
-
getGraphrepresentation
public int[][] getGraphrepresentation()- Returns:
- Graph representation
-
createRandomNewSolution
public abstract ArrayList<ElementOfCombinatoricsProb> createRandomNewSolution(ArrayList<ElementOfCombinatoricsProb> currSol) create a solution that changes the solution currSol a little bit (i.e.: for TSP: swap 2 cities; for KnapSack: add a random element) for currSol == null: create a random solution- Parameters:
currSol- the current solution- Returns:
- the solution
-
evaluate
evaluates the solution- Parameters:
sol- some solution- Returns:
- the target function for sol
-
isValid
checks if a given solution is valid under all constraints- Parameters:
sol- some solution- Returns:
- true iff the solution is valid
-
getHeuristicValue
public abstract Double getHeuristicValue(ElementOfCombinatoricsProb solutionComponent, Integer getCurrentIndex, ElementOfCombinatoricsProb initialReference, ElementOfCombinatoricsProb[] sol) for Ant optimization: give a chance between 0 and 1 for accepting solutionComponent to the solution sol- Parameters:
solutionComponent- : Element to be checked *getCurrentIndex- : the length of the solutioninitialReference- : default starting point for the solution (the first Element in the solution)sol- : array representation of a solution (needed for Ant optimization)- Returns:
- the heuristic value
-
getRepresentation
public abstract double[][] getRepresentation()for Ant optimization: represent the problem as an adjacence matrix- Returns:
- representation
-