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_solution

best solution

Type:

Solution

best_obj_value

incumbent objective value

Type:

float

solution

solution

Type:

Solution

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) –

closeProcess()[source]

process of ending of search

during_solver_message(head)[source]
Parameters:

head (str) – character of header

getObjValue(solution)[source]

calculate objective value

Parameters:

solution (Solution) –

Return type:

int or float

recordLog()[source]

write log in self.log

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

reset()[source]

reset solving log and status

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)

startProcess(*args)[source]

process of beginning of search

updateSolution(solution, obj_value=None)[source]

update self.best_solution

Parameters:
  • solution (Solution) –

  • obj_value (None or float) – objective value of solution, if it is None, then calculate objective value in this function