Class CombinatoricsProblem

All Implemented Interfaces:
Serializable, Cloneable, Iterable<OptProbElement>, Collection<OptProbElement>, Set<OptProbElement>
Direct Known Subclasses:
KnapSack, TravelingSalesman

public abstract class CombinatoricsProblem extends GeneralConstraintSatisfactionProblem
This class implements a combinatorial optimization problem
Author:
Sebastian Franke
See Also:
  • Field Details

  • Constructor Details

    • CombinatoricsProblem

      public CombinatoricsProblem(List<ElementOfCombinatoricsProb> elements, int[][] graphRepresantation)
      constructor
      Parameters:
      elements - elements
      graphRepresantation - problem
  • Method Details

    • createDifference

      Parameters:
      c - the List to be subtracted from "this" List
      Returns:
      the differnece of the lists
    • sumOfWeights

      public abstract double sumOfWeights(ArrayList<ElementOfCombinatoricsProb> sol)
      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 solution
      minIterations - minimum iterations
      maxIteration - maximum iterations
      threshold - 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

      public abstract double evaluate(ArrayList<ElementOfCombinatoricsProb> sol)
      evaluates the solution
      Parameters:
      sol - some solution
      Returns:
      the target function for sol
    • isValid

      public abstract boolean isValid(ArrayList<ElementOfCombinatoricsProb> sol)
      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 solution
      initialReference - : 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