Solver Base class
- class flopt.solvers.base.BaseSearch[source]
Base Search Class
For developer;
self.best_solution has references to variables defined by the user
self.getObjValue(solution) returns the objective value by the solution
self.recordLog() records the log (objective value, time, iteratino) for each time incumbent solution (self.bset_solution) is updated.
- name
name of solver
- Type:
str
- feasible_guard
type of guarder to keep feasibility of solution
- Type:
str
- can_solve_problems
problem names can be solved by this solver
- Type:
list of {‘blackbox’, ‘lp’, ‘qp’, ‘permutation’}
- best_obj_value
incumbent objective value
- Type:
float
- obj
objective function
- Type:
ObjectiveFunction
- timelimit
timelimit, unit is second
- Type:
float
- lowerbound
solver terminates when it obtains the solution whose objective value is lower than this
- Type:
float
- msg
if true, then display logs
- Type:
bool
- callbacks
List of callback functions that are invoked at the end of each trial. Each function must accept three parameters with the following types in this order: list of solution object, best_solution, best_obj_value
- Type:
list of function
- log
Solver Log class
- Type:
Log
- build_time
time to build the problem for solver
- Type:
float
- start_time
start time at calling solve()
- Type:
float
- trial_ix
number of trials
- Type:
int
- max_k
number of save solutions
- Type:
int
- save_solution
flag for coping solution to log
- Type:
bool
- availableProblemType(problem_type)[source]
- Parameters:
problem_type (dict) – key is “Variable”, “Objective”, “Constraint”
- Returns:
algorithm names that can solve the problem
- Return type:
list of str
Examples
import flopt.constants import flopt.solvers problem_type = dict( Variable=flopt.constants.VariableType.Number, Objective=flopt.constants.ExpressionType.BlackBox, Constraint=None ) solver.availableProblemType(problem_type)
- callback(solutions)[source]
execute user defined callback function
- Parameters:
solutions (list of Solution) –
- getObjValue(solution)[source]
calculate objective value
- Parameters:
solution (Solution) –
- Return type:
int or float
- registerSolution(solution, obj_value=None, msg_tol=None)[source]
update solution if the solution is better than the incumbent
- Parameters:
solution (Solution) –
obj_value (None or float) – objective value of solution, if it is None, then calculate objective value in this function
msg_tol (None of float) – output the message when solution is updated greater than msg_tol
- setParams(params=None, **kwargs)[source]
set some parameters
- Parameters:
params (dict) – {paramname: paramvalue}
- solve(solution, objective, constraints, prob, msg=False)[source]
solve the problem of (solution, objective, constraints)
- Parameters:
solution (Solution) – solution object
objective (Expression) – objective object
constraints (list of Constraint) – list of constriants objects
prob (Problem) – problem to be solved
msg (bool) – if true, then display logs
- Returns:
status (flopt.SolverTerminateState)
Log (Log)
running_time (float)