Class MispProblem

java.lang.Object
org.ddolib.examples.nolayer.misp.MispProblem
All Implemented Interfaces:
Problem<MispState>

public class MispProblem extends Object implements Problem<MispState>
The Maximum Independent Set Problem (MISP), in the no-layer modeling API.

The problem is represented as an undirected graph where each node has a weight, and the goal is to select a subset of non-adjacent nodes (an independent set) that maximizes the total weight. Since the library only minimizes, weights are negated in transitionCost(org.ddolib.examples.nolayer.misp.MispState, int) and evaluate(java.util.List<java.lang.Integer>).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    The number of nodes in the graph.
    final BitSet[]
    For each node, the set of nodes it is adjacent to.
    final int[]
    The weight of each node.
  • Constructor Summary

    Constructors
    Constructor
    Description
    MispProblem(BitSet[] neighbors, int[] weight)
    Creates a new, unnamed MISP instance with the given adjacency and weights.
    MispProblem(BitSet[] neighbors, int[] weight, String name)
    Creates a new MISP instance with the given adjacency and weights.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the domain of possible labels/actions from a given state.
    double
    evaluate(List<Integer> solution)
    Given a solution (a sequence of applied labels), returns its value and checks if the solution respects the problem's constraints.
    Reads a MISP instance from a DOT file, where each node line may carry a weight= attribute (defaulting to 1 when absent) and edges are listed as source -- target lines.
    Returns the initial state of the problem.
    double
    Returns the initial objective value associated with the initial state.
    boolean
    Checks whether the given state is a target (sink) state.
     
    transition(MispState state, int label)
    Applies a label/action to a state, computing the next state according to the problem's transition function.
    double
    transitionCost(MispState state, int label)
    Computes the change in objective value resulting from applying a label to a given state.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.ddolib.nolayer.modeling.Problem

    hasNonNegativeCosts, optimalValue
  • Field Details

    • neighbors

      public final BitSet[] neighbors
      For each node, the set of nodes it is adjacent to.
    • weight

      public final int[] weight
      The weight of each node.
    • nbVars

      public final int nbVars
      The number of nodes in the graph.
  • Constructor Details

    • MispProblem

      public MispProblem(BitSet[] neighbors, int[] weight, String name)
      Creates a new MISP instance with the given adjacency and weights.
      Parameters:
      neighbors - for each node, the set of nodes it is adjacent to
      weight - the weight of each node
      name - a name identifying this instance, typically the file it was loaded from
    • MispProblem

      public MispProblem(BitSet[] neighbors, int[] weight)
      Creates a new, unnamed MISP instance with the given adjacency and weights.
      Parameters:
      neighbors - for each node, the set of nodes it is adjacent to
      weight - the weight of each node
  • Method Details

    • fromFile

      public static MispProblem fromFile(String fname) throws IOException
      Reads a MISP instance from a DOT file, where each node line may carry a weight= attribute (defaulting to 1 when absent) and edges are listed as source -- target lines.
      Parameters:
      fname - the path to the DOT file describing the instance
      Returns:
      the MISP instance read from the file
      Throws:
      IOException - if the file cannot be read
    • initialState

      public MispState initialState()
      Description copied from interface: Problem
      Returns the initial state of the problem.
      Specified by:
      initialState in interface Problem<MispState>
      Returns:
      the state representing the starting point of the optimization
    • initialValue

      public double initialValue()
      Description copied from interface: Problem
      Returns the initial objective value associated with the initial state.
      Specified by:
      initialValue in interface Problem<MispState>
      Returns:
      the starting value of the objective function
    • isTarget

      public boolean isTarget(MispState state)
      Description copied from interface: Problem
      Checks whether the given state is a target (sink) state.
      Specified by:
      isTarget in interface Problem<MispState>
      Parameters:
      state - the current state
      Returns:
      true if the state is a target state, false otherwise
    • domain

      public Iterator<Integer> domain(MispState state)
      Description copied from interface: Problem
      Returns the domain of possible labels/actions from a given state.
      Specified by:
      domain in interface Problem<MispState>
      Parameters:
      state - the current state
      Returns:
      an iterator over all feasible labels for the given state
    • transition

      public MispState transition(MispState state, int label)
      Description copied from interface: Problem
      Applies a label/action to a state, computing the next state according to the problem's transition function.
      Specified by:
      transition in interface Problem<MispState>
      Parameters:
      state - the state from which the transition originates
      label - the label to apply
      Returns:
      the resulting state after applying the label
    • transitionCost

      public double transitionCost(MispState state, int label)
      Description copied from interface: Problem
      Computes the change in objective value resulting from applying a label to a given state.
      Specified by:
      transitionCost in interface Problem<MispState>
      Parameters:
      state - the state from which the transition originates
      label - the label to apply
      Returns:
      the incremental objective cost/value associated with this label
    • evaluate

      public double evaluate(List<Integer> solution) throws InvalidSolutionException
      Description copied from interface: Problem
      Given a solution (a sequence of applied labels), returns its value and checks if the solution respects the problem's constraints.
      Specified by:
      evaluate in interface Problem<MispState>
      Parameters:
      solution - a solution of the problem (sequence of labels)
      Returns:
      the value of the input solution
      Throws:
      InvalidSolutionException - if the solution does not respect problem's constraints
    • toString

      public String toString()
      Overrides:
      toString in class Object