Package org.ddolib.examples.mcp
Class MCPProblem
java.lang.Object
org.ddolib.examples.mcp.MCPProblem
Represents an instance of the Maximum Cut Problem (MCP).
In the MCP, given a weighted undirected graph, the goal is to partition the nodes into two sets (S and T) such that the sum of the weights of edges between the sets is maximized.
This class implements the Problem interface and provides methods for:
- Initializing the problem from a graph or a file.
- Defining the decision domain (which partition a node belongs to).
- Computing transitions and transition costs between states.
- Accessing the initial state and value, and optional optimal value.
Constants S and T are used to model decisions: placing a node in
partition S or T, respectively.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMCPProblem(String fname) Constructs an MCP problem by reading an instance from a file.MCPProblem(Graph graph) Constructs an MCP problem from a given graph.MCPProblem(Graph graph, Double optimal) Constructs an MCP problem from a given graph and known optimal value. -
Method Summary
Modifier and TypeMethodDescriptionReturns the domain of possible values for a given variable when applied to a specific state.doubleevaluate(int[] solution) Given a solution such thatsolution[i]is the value of the variablex_i, returns the value of this solution and checks if the solution respects the problem's constraints.Returns the initial state of the problem.doubleReturns the initial objective value associated with the initial state.intnbVars()Returns the known optimal value of the problem, if available.toString()transition(MCPState state, Decision decision) Applies a decision to a state, computing the next state according to the problem's transition function.doubletransitionCost(MCPState state, Decision decision) Computes the change in objective value resulting from applying a decision to a given state.
-
Field Details
-
S
public final int SConstant to model decision "put in partitionS".- See Also:
-
T
public final int TConstant to model decision "put in partitionT".- See Also:
-
optimal
Optional known optimal value for the problem instance.
-
-
Constructor Details
-
MCPProblem
Constructs an MCP problem from a given graph.- Parameters:
graph- the graph representing the instance
-
MCPProblem
Constructs an MCP problem from a given graph and known optimal value.- Parameters:
graph- the graph representing the instanceoptimal- the known optimal value of the instance
-
MCPProblem
Constructs an MCP problem by reading an instance from a file.The file should contain the number of nodes and the adjacency matrix of weights, optionally including the optimal solution value.
- Parameters:
fname- the path to the file containing the instance- Throws:
IOException- if the file cannot be read
-
-
Method Details
-
toString
-
nbVars
public int nbVars() -
initialState
Description copied from interface:ProblemReturns the initial state of the problem.- Specified by:
initialStatein interfaceProblem<MCPState>- 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<MCPState>- Returns:
- the starting value of the objective function
-
domain
Description copied from interface:ProblemReturns the domain of possible values for a given variable when applied to a specific state. -
transition
Description copied from interface:ProblemApplies a decision to a state, computing the next state according to the problem's transition function.- Specified by:
transitionin interfaceProblem<MCPState>- Parameters:
state- the state from which the transition originatesdecision- the decision to apply- Returns:
- the resulting state after applying the decision
-
transitionCost
Description copied from interface:ProblemComputes the change in objective value resulting from applying a decision to a given state.- Specified by:
transitionCostin interfaceProblem<MCPState>- Parameters:
state- the state from which the transition originatesdecision- the decision to apply- Returns:
- the incremental objective cost/value associated with this decision
-
optimalValue
Description copied from interface:ProblemReturns the known optimal value of the problem, if available.Note: This value should correspond to the expected output of the solver. For maximization problems, be careful with negative values.
- Specified by:
optimalValuein interfaceProblem<MCPState>- Returns:
- an
Optionalcontaining the known optimal value, or empty if unknown
-
evaluate
Description copied from interface:ProblemGiven a solution such thatsolution[i]is the value of the variablex_i, returns the value of this solution and checks if the solution respects the problem's constraints.Note: For maximization problems, the returned value is minus the computed value.
- Specified by:
evaluatein interfaceProblem<MCPState>- Parameters:
solution- A solution of the problem.- Returns:
- The value of the input solution
- Throws:
InvalidSolutionException- If the solution does not respect problem's constraints.
-