Class CombinatoricsProblem
java.lang.Object
java.util.AbstractCollection<OptProbElement>
java.util.AbstractSet<OptProbElement>
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
Modifier and TypeFieldDescriptionelementsstatic final int
Static constant for the type "maximization"static final int
Static constant for the type "minimization" -
Constructor Summary
ConstructorDescriptionCombinatoricsProblem
(List<ElementOfCombinatoricsProb> elements, int[][] graphRepresantation) constructor -
Method Summary
Modifier and TypeMethodDescriptionReturn the differnece of the listsabstract 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 double
evaluates the solutionformNeighborhood
(ArrayList<ElementOfCombinatoricsProb> currSol, int minIterations, int maxIteration, double threshold) Return neighborhoodint[][]
Return Graph representationabstract 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 solabstract double[][]
for Ant optimization: represent the problem as an adjacence matrixabstract boolean
checks if a given solution is valid under all constraintsabstract double
Return if the solution sol is valid under the constraints of the problemMethods inherited from class java.util.HashSet
add, clear, clone, contains, isEmpty, iterator, newHashSet, remove, size, spliterator, toArray, toArray
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toString
Methods 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) Return the differnece of the lists- Parameters:
c
- the List to be subtracted from "this" List- Returns:
- the differnece of the lists
-
sumOfWeights
Return if the solution sol is valid under the constraints of the problem- 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) Return neighborhood- Parameters:
currSol
- current solutionminIterations
- minimum iterationsmaxIteration
- maximum iterationsthreshold
- threshold- Returns:
- neighborhood
-
getGraphrepresentation
public int[][] getGraphrepresentation()Return Graph representation- 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
-