Class SRFLPProblem
- All Implemented Interfaces:
Problem<SRFLPState>
This class implements the Problem interface and provides methods to:
- Access the number of departments (
nbVars()) - Get the initial state of the problem (
initialState()) - Compute the cost of transitions (
transitionCost(SRFLPState, Decision)) - Compute the next state after a decision (
transition(SRFLPState, Decision)) - Provide the domain of selectable departments for a given state (
domain(SRFLPState, int)) - Optionally return the known optimal value (
optimalValue())
Instances can be created either from raw arrays of lengths and flows, or by reading from a file with a specific format. The flows matrix must be symmetric.
This class is intended to be used with solvers such as A*, Decision Diagrams (DDO),
or other combinatorial optimization frameworks that support the Problem interface.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSRFLPProblem(int[] lengths, int[][] flows) Constructs a new SRFLP instance with given lengths and flows.SRFLPProblem(int[] lengths, int[][] flows, Optional<Double> optimal) Constructs a new SRFLP instance with given lengths, flows, and optional known optimal.SRFLPProblem(String fname) Reads an SRFLP instance from a file. -
Method Summary
Modifier and TypeMethodDescriptiondomain(SRFLPState state, int var) Returns 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.Computes a constant initial value accounting for half the contribution of each department pair.doubleReturns a constant accounting for all contributions of half department lengths.intnbVars()Returns the known optimal value of the problem, if available.toString()transition(SRFLPState state, Decision decision) Applies a decision to a state, computing the next state according to the problem's transition function.doubletransitionCost(SRFLPState state, Decision decision) Computes the change in objective value resulting from applying a decision to a given state.
-
Constructor Details
-
SRFLPProblem
Constructs a new SRFLP instance with given lengths, flows, and optional known optimal.- Parameters:
lengths- The lengths of the departments.flows- The traffic flow matrix between departments (must be symmetric).optimal- Optional known optimal value for the instance.- Throws:
IllegalArgumentException- if flows is not symmetric.
-
SRFLPProblem
public SRFLPProblem(int[] lengths, int[][] flows) Constructs a new SRFLP instance with given lengths and flows.- Parameters:
lengths- The lengths of the departments.flows- The traffic flow matrix between departments (must be symmetric).
-
SRFLPProblem
Reads an SRFLP instance from a file.The file should contain the number of departments on the first line, optionally followed by the known optimal value. The second line lists the department lengths, and subsequent lines provide the symmetric flow matrix.
- Parameters:
fname- The filename to read.- Throws:
IOException- if the file cannot be read.
-
-
Method Details
-
nbVars
public int nbVars()- Specified by:
nbVarsin interfaceProblem<SRFLPState>- Returns:
- the total number of decision variables in this problem
-
initialState
Computes a constant initial value accounting for half the contribution of each department pair.- Specified by:
initialStatein interfaceProblem<SRFLPState>- Returns:
- The root value of the problem.
-
initialValue
public double initialValue()Returns a constant accounting for all contributions of half department lengths.- Specified by:
initialValuein interfaceProblem<SRFLPState>- Returns:
- The problem's initial value
-
domain
Description copied from interface:ProblemReturns the domain of possible values for a given variable when applied to a specific state.- Specified by:
domainin interfaceProblem<SRFLPState>- Parameters:
state- the current statevar- the variable index whose domain is queried- Returns:
- an iterator over all feasible values for the variable in this 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<SRFLPState>- 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<SRFLPState>- 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<SRFLPState>- 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<SRFLPState>- 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.
-
toString
-