Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary doc #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ __pycache__/
gurobi.log
ks_engine/__pycache__/
instances/*
sphinx_doc/build/
*.csv
*.dat
*.sol
*.sh
*.sh

2 changes: 1 addition & 1 deletion ks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main():
else:
if sol_file := conf["SOLUTION_FILE"]:
sol.save_as_sol_file(sol_file)

print("Solution:", sol.value)
sol.debug.export_csv(conf["DEBUG"], False)

Expand Down
36 changes: 6 additions & 30 deletions ks_engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,11 @@

# Copyright (c) 2019 Filippo Ranza <[email protected]>

"""
ks_engine
=========

An implementation of the Kernel Search Heuristic method

Available functions
-------------------
kernel_search
run the Kernel Search Heuristic

config_loader
load ks_engine (and eventually client code) configuration
from given YAML file



Available subpackages
---------------------
kernel_utils
contains some basic initial kernel generators
and a generator 'factory'

bucket_utils
contains some basic bucket generators
and a generator 'factory'

"""

from .kernel_search import kernel_search, KernelMethods
from .config_loader import load_config
from .kernel_algorithms import *
from .kernel_algorithms import * # noqa


__all__ = ['kernel_search',
'KernelMethods',
'load_config']
34 changes: 16 additions & 18 deletions ks_engine/config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@
}


def check_config(conf):
def check_config(conf: dict):
"""
Check the provided configuration file.

:param conf: A dictionary representing the configuration file.
:type conf: dict
:raises ValueError: If the type of every key in the dictionary is wrong.
"""
for k, v in DEFAULT_CONF.items():
c = conf[k]
if not (type(c) is type(v)):
Expand All @@ -34,28 +41,19 @@ def check_config(conf):
)


def load_config(file_name):
def load_config(file_name: str):
"""
Load the configuration from the given file.

Parameters
----------
file_name : str
path to the YAML configuration file

Raises
------
ValueError
if some variable in the given configuration
does not have the same type of the variables
in the default configuration. Other variables
:param file_name: path to the YAML configuration file.
:type file_name: str
:raises ValueError: if some variable in the given configuration
does not have the same type of the variables
in the default configuration. Other variables
are not checked.

Returns
-------
config: dict
map configuration variable name into
:return: map configuration variable name into
their values
:rtype: dict
"""
if not file_name:
return DEFAULT_CONF
Expand Down
Loading