kep_solver.fileio module
This module contains file IO functions.
- read_json(filename)
Read an instance in JSON format from the given file
- Parameters:
filename (
str) – The name of the file containing the JSON instance- Return type:
- Returns:
the corresponding Instance
- parse_json(jsonstring)
Read an instance in JSON format from the given string
- Parameters:
jsonstring (
str) – A string holding a JSON representation of the instance- Return type:
- Returns:
the corresponding Instance
- parse_json_v1(json_obj)
Read an instance in JSON v1 format from the given string
- Parameters:
jsonstring – A string holding a JSON representation of the instance
- Return type:
- Returns:
the corresponding Instance
- parse_json_v2(json_obj)
Read an instance in JSON v2 format from the given string
- Parameters:
jsonstring – A string holding a JSON representation of the instance
- Return type:
- Returns:
the corresponding Instance
- read_xml(filename)
Read an instance in XML format from the given file
- Parameters:
filename (
str) – The name of the file containing the XML instance- Return type:
- Returns:
the corresponding Instance
- parse_xml(xmlstring)
Read an instance in XML format from the given string
- Parameters:
xmlstring (
str) – A string holding a XML representation of the instance- Return type:
- Returns:
the corresponding Instance
- read_yaml(filename)
Read an instance in YAML format from the given file
- Parameters:
filename (
str) – The name of the file containing the YAML instance- Return type:
- Returns:
the corresponding Instance
- parse_yaml(yamlstring)
Read an instance in YAML format from the given string
- Parameters:
xmlstring – A string holding a YAML representation of the instance
- Return type:
- Returns:
the corresponding Instance
- read_compressed(filename)
Read a compressed file containing a KEP instance. Will attempt to detect the correct file format if possible.
- Parameters:
filename (
str) – The name of the file containing the instance- Return type:
- Returns:
the corresponding Instance
- read_file(filename)
Read a file containing a KEP instance. Will attempt to detect the correct file format if possible.
- Parameters:
filename (
str) – The name of the file containing the instance- Return type:
- Returns:
the corresponding Instance
- class UKJson(model, programme, solution)
Bases:
objectA class for outputing JSON-formatted results in the style prescribed by the UK KEP and NHSBT.
- __init__(model, programme, solution)
- to_string()
Return a string representing the solution as a JSON object.
- Return type:
str- Returns:
A string representing the JSON.
- write(output)
Write the details to a JSON file, or file-like object.
- Parameters:
output (
TextIO) – A file-like object where output will be written.
- class UKXML(model, programme, solution)
Bases:
objectA class for outputing XML-formatted results in the style prescribed by the UK KEP and NHSBT.
- __init__(model, programme, solution)
- to_string()
Return a string representing the solution as a JSON object.
- Return type:
str- Returns:
A string representing the JSON.
- write(output)
Write the details to a XML file, or file-like object.
- Parameters:
output (
TextIO) – A file-like object where output will be written.
- write_dynamic_results(matchruns, exchanged, outfile)
Save the results of a dynamic simulation to a JSON file.
- Parameters:
matchruns (
list[tuple[int,Instance,Model,Solution]]) – A list of the match runs performed. Each entry is a tuple containing the period in which the match run occured, the input Instance, the Model used to solve the problem, and the Solution.exchanged (
dict[int,list[Exchange]]) – A dictionary mapping each period to the list of exchanges performed in that period.
- Return type:
None