Package org.ddolib.examples.nolayer.misp
Class MispProblem
java.lang.Object
org.ddolib.examples.nolayer.misp.MispProblem
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 -
Constructor Summary
ConstructorsConstructorDescriptionMispProblem(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 TypeMethodDescriptionReturns the domain of possible labels/actions from a given state.doubleGiven a solution (a sequence of applied labels), returns its value and checks if the solution respects the problem's constraints.static MispProblemReads a MISP instance from a DOT file, where each node line may carry aweight=attribute (defaulting to1when absent) and edges are listed assource -- targetlines.Returns the initial state of the problem.doubleReturns the initial objective value associated with the initial state.booleanChecks whether the given state is a target (sink) state.toString()transition(MispState state, int label) Applies a label/action to a state, computing the next state according to the problem's transition function.doubletransitionCost(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, waitMethods inherited from interface org.ddolib.nolayer.modeling.Problem
hasNonNegativeCosts, optimalValue
-
Field Details
-
neighbors
For each node, the set of nodes it is adjacent to. -
weight
public final int[] weightThe weight of each node. -
nbVars
public final int nbVarsThe number of nodes in the graph.
-
-
Constructor Details
-
MispProblem
Creates a new MISP instance with the given adjacency and weights.- Parameters:
neighbors- for each node, the set of nodes it is adjacent toweight- the weight of each nodename- a name identifying this instance, typically the file it was loaded from
-
MispProblem
Creates a new, unnamed MISP instance with the given adjacency and weights.- Parameters:
neighbors- for each node, the set of nodes it is adjacent toweight- the weight of each node
-
-
Method Details
-
fromFile
Reads a MISP instance from a DOT file, where each node line may carry aweight=attribute (defaulting to1when absent) and edges are listed assource -- targetlines.- 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
Description copied from interface:ProblemReturns the initial state of the problem.- Specified by:
initialStatein interfaceProblem<MispState>- Returns:
- the state representing the starting point of the optimization
-
initialValue
public double initialValue()Description copied from interface:ProblemReturns the initial objective value associated with the initial state.- Specified by:
initialValuein interfaceProblem<MispState>- Returns:
- the starting value of the objective function
-
isTarget
Description copied from interface:ProblemChecks whether the given state is a target (sink) state. -
domain
Description copied from interface:ProblemReturns the domain of possible labels/actions from a given state. -
transition
Description copied from interface:ProblemApplies a label/action to a state, computing the next state according to the problem's transition function.- Specified by:
transitionin interfaceProblem<MispState>- Parameters:
state- the state from which the transition originateslabel- the label to apply- Returns:
- the resulting state after applying the label
-
transitionCost
Description copied from interface:ProblemComputes the change in objective value resulting from applying a label to a given state.- Specified by:
transitionCostin interfaceProblem<MispState>- Parameters:
state- the state from which the transition originateslabel- the label to apply- Returns:
- the incremental objective cost/value associated with this label
-
evaluate
Description copied from interface:ProblemGiven a solution (a sequence of applied labels), returns its value and checks if the solution respects the problem's constraints.- Specified by:
evaluatein interfaceProblem<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
-