Python API
import ramparils
The module exposes a single function.
specialize
ramparils.specialize(strategy, scenario, cache_db, cores=0)
Specialize a strategy on a set of benchmark instances using FocusedILS.
Runs Iterated Local Search starting from strategy, evaluating
(configuration, instance) pairs in parallel, and returns the best
configuration found within the time budget.
Results are cached in a persistent SQLite database so that repeated calls with the same algorithm and instances never redo solver invocations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy
|
dict[str, str]
|
Initial parameter configuration as |
required |
scenario
|
dict
|
Tuning scenario as a dict. Required keys:
Exactly one of the following must be supplied to specify instances:
Optional keys:
|
required |
cache_db
|
str
|
Path to the SQLite cache file. Created if it does not exist.
Use |
required |
cores
|
int
|
Number of parallel worker threads. |
0
|
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
The best configuration found, as |
dict[str, str]
|
Only active parameters are included (inactive conditional parameters |
dict[str, str]
|
are omitted). |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the scenario is invalid, the instance list is empty, the paramfile cannot be parsed, or the cache cannot be opened. |
Example
result = ramparils.specialize( ... strategy={"alpha": "1.189", "rho": "0.5"}, ... scenario={ ... "algo": "ruby /path/to/solver_wrapper.rb", ... "paramfile": "/path/to/solver.params", ... "instances": ["/path/to/inst1.cnf", "/path/to/inst2.cnf"], ... "cutoff_time": 5.0, ... "tuner_timeout": 120.0, ... }, ... cache_db="/tmp/ramparils_cache.db", ... cores=8, ... ) print(result) {'alpha': '1.256', 'rho': '0.5'}
Example
import ramparils
result = ramparils.specialize(
strategy={
"alpha": "1.189",
"rho": "0.5",
"ps": "0.1",
"wp": "0.03",
},
scenario={
"algo": "ruby /path/to/saps_wrapper.rb",
"paramfile": "/path/to/saps.params",
"instances": [
"/path/to/instances/inst1.cnf",
"/path/to/instances/inst2.cnf",
],
"cutoff_time": 5.0,
"tuner_timeout": 120.0,
},
cache_db="/tmp/ramparils_cache.db",
cores=8,
)
print("Best config found:")
for k, v in sorted(result.items()):
print(f" {k} = {v}")
See examples/saps_python.py for a runnable example.