| Function | about_equal | Return True if the floating point number ${a} and ${b} are about equal. |
| Function | args_to_dict | return a dict from a list of "name=value" strings. |
| Class | ObserverOptions | a dict with observer options which can be passed to the (C-based) Observer via the as_string property. |
| Class | ProblemNonAnytime | The non-anytime problem class. |
| Class | SameFunction | Count the number of consecutive instances of the same function. |
| Class | MiniPrint | print dimension when changed and a single symbol for each call. |
| Class | ShortInfo | print minimal info during benchmarking. |
| Function | ascetime | return elapsed time as str. |
| Function | print_flush | print without newline but with flush |
return a dict from a list of "name=value" strings.
args come in the form of a list of "name=value" strings
without spaces, like ["budget_multiplier=100"].
Return dict(arg.split(split) for arg in args) in the most
basic case, but additionally (i) checks that the keys of this
dict are known names, (ii) evaluates the values in some cases
and (iii) handles specials.
know_names is an iterable (dict or list or tuple) of strings.
If know_names is None, all args are processed, otherwise a
ValueError is raised for unknown names. This is useful if we
want to re-assign variables (overwrite default values) and avoid
spelling mistakes pass silently.
The value is processed as a Python literal with ast.literal_eval
or remains a str when this is unsuccessful.
specials is a dict and can currently only contain 'batch',
followed by "name1/name2" as value. name1 and name2 are
then assigned from the values in arg, for example to 2 and 4 with
batch=2/4.
A main usecase is to process sys.argv[1:] into a dict in a
python script, like:
command_line_dict = args_to_dict(sys.argv[1:], globals()) globals().update(command_line_dict)
>>> import cocoex >>> d = cocoex.utilities.args_to_dict(["budget=2.3", "bed=bed-name", "number=4"], ... ["budget", "bed", "number", "whatever"]) >>> len(d) 3 >>> assert d['bed'] == 'bed-name' >>> assert isinstance(d["budget"], float)