/
solver.go
131 lines (117 loc) · 4.85 KB
/
solver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package mip
import "time"
// Solver exposes an API to run a MIP solver
//
// model := mip.NewModel()
//
// // build the model
//
// provider := "my_favorite_solver"
//
// solver, err := NewSolver(provider, model)
//
// solution, err := solver.Solve(mip.DefaultSolverOptions())
type Solver interface {
// Solve is the entrypoint to solve the model associated with
// the invoking solver. Returns a solution when the invoking solver
// reaches a conclusion.
Solve(options SolveOptions) (Solution, error)
}
// SolveOptions interface to options for back-end solver.
type SolveOptions interface {
// FloatParameters returns all float parameter settings.
FloatParameters() FloatSolverParameterSettings
// GetFloatParameter returns value set for parameter, returns error if no
// such parameter has been set.
GetFloatParameter(parameter SolverParameter) (float64, error)
// GetIntParameter returns value set for parameter, returns error if no
// such parameter has been set.
GetIntParameter(parameter SolverParameter) (int64, error)
// GetStringParameter returns value set for parameter, returns error if no
// such parameter has been set.
GetStringParameter(parameter SolverParameter) (string, error)
// IntParameters returns all int parameter settings.
IntParameters() IntSolverParameterSettings
// MaximumDuration returns maximum duration of a Solver.Solve invocation.
MaximumDuration() time.Duration
// MIPGapAbsolute returns the absolute gap stopping value. If the problem
// is an integer problem the solver will stop if the gap between the relaxed
// problem and the best found integer problem is less than this value.
MIPGapAbsolute() float64
// MIPGapRelative returns the relative gap stopping value. If the problem
// is an integer problem the solver will stop if the relative gap between
// the relaxed problem and the best found integer problem is less than
// this value.
MIPGapRelative() float64
// SetFloatParameter specifies the value to use for parameter, this is
// back-end-solver specific.
SetFloatParameter(parameter SolverParameter, value float64)
// SetIntParameter specifies the value to use for parameter, this is
// back-end-solver specific.
SetIntParameter(parameter SolverParameter, value int64)
// SetMaximumDuration specifies the maximum duration of a Solver.Solve
// invocation.
SetMaximumDuration(duration time.Duration) error
// SetMIPGapAbsolute specifies the absolute gap stopping value, only
// used in case the problem is an integer solution, raises an error if
// value is not strictly positive (> 0).
SetMIPGapAbsolute(value float64) error
// SetMIPGapRelative specifies the relative gap stopping value, only
// used in case the problem is an integer solution, raises an error if
// value is less than zero or larger or equal to one.
SetMIPGapRelative(value float64) error
// SetStringParameter specifies the value to use for parameter, this is
// back-end-solver specific.
SetStringParameter(parameter SolverParameter, value string)
// SetVerbosity specifies the verbosity level of the underlying
// back-end solver. Forwards output to std out.
SetVerbosity(verbosity Verbosity)
// StringParameters returns all string parameter settings
StringParameters() StringSolverParameterSettings
// Verbosity returns the configured verbosity level of the
// underlying back-end solver.
Verbosity() Verbosity
}
// Verbosity specifies the level of verbosity of the back-end solver.
type Verbosity int
const (
// Off logs nothing.
Off Verbosity = iota
// Low logs essentials, depends on the back-end solver.
Low
// Medium logs essentials plus high level events,
// depends on the back-end solver.
Medium
// High logs everything the underlying logs,
// depends on the back-end solver.
High
)
// SolverParameter identifier for parameters in the back-end solver.
type SolverParameter int
// SolverProvider identifier for a back-end solver.
type SolverProvider string
// GetSolverParameter interface to retrieve a solver parameter.
type GetSolverParameter interface {
SolverParameter() SolverParameter
}
// FloatSolverParameterSetting interface for setting of type float64.
type FloatSolverParameterSetting interface {
GetSolverParameter
Value() float64
}
// FloatSolverParameterSettings slice of FloatSolverParameterSetting.
type FloatSolverParameterSettings []FloatSolverParameterSetting
// IntSolverParameterSetting interface for setting of type int64.
type IntSolverParameterSetting interface {
GetSolverParameter
Value() int64
}
// IntSolverParameterSettings slice of IntSolverParameterSetting.
type IntSolverParameterSettings []IntSolverParameterSetting
// StringSolverParameterSetting interface for setting of type string.
type StringSolverParameterSetting interface {
GetSolverParameter
Value() string
}
// StringSolverParameterSettings slice of StringSolverParameterSetting.
type StringSolverParameterSettings []StringSolverParameterSetting