Class TSPRelax

java.lang.Object
org.ddolib.examples.tsp.TSPRelax
All Implemented Interfaces:
Relaxation<TSPState>

public class TSPRelax extends Object implements Relaxation<TSPState>
Implementation of a relaxation for the Traveling Salesman Problem (TSP).

This class implements the Relaxation interface for TSPState. It provides methods to merge multiple states into a single relaxed state and to adjust the cost of transitions in a relaxed context.

In this implementation:

See Also:
  • Constructor Details

    • TSPRelax

      public TSPRelax(TSPProblem problem)
      Constructs a relaxation for a given TSP problem.
      Parameters:
      problem - the TSP problem instance to be relaxed
  • Method Details

    • mergeStates

      public TSPState mergeStates(Iterator<TSPState> states)
      Merges multiple TSPState instances into a single relaxed state.

      The resulting state has its "toVisit" and "current" sets as the union of the corresponding sets from all input states.

      Specified by:
      mergeStates in interface Relaxation<TSPState>
      Parameters:
      states - an iterator over the states to merge
      Returns:
      a new TSPState representing the merged state
    • relaxEdge

      public double relaxEdge(TSPState from, TSPState to, TSPState merged, Decision d, double cost)
      Relaxes the cost of a transition between states.

      In this implementation, the cost is not modified and the original cost is returned.

      Specified by:
      relaxEdge in interface Relaxation<TSPState>
      Parameters:
      from - the state before the transition
      to - the state after the transition
      merged - the merged state (if any)
      d - the decision causing the transition
      cost - the original cost of the transition
      Returns:
      the relaxed cost of the transition (same as the original cost)