Reference¶
scoreo package¶
scoreo.course module¶
Classes and functions for courses and controls.
- class Control(code, x, y)¶
Bases:
object
A Class representing an orienteering control with position, code and score.
- Parameters:
code (str)
x (str)
y (str)
- multiplier = 10¶
- class Course¶
Bases:
object
A Class representing a collection of controls.
- display_controls(solution)¶
Display the controls in a course based on their ‘map_x’ and ‘map_y’ attributes.
- Return type:
None
- Parameters:
solution (list[int])
- estimate_max_distance()¶
Estimate the initial max distance for visiting all controls.
Algorithm: Circumference of the bounding rectangle.
- Return type:
int
- Returns:
The max distance in meters.
- get_stop_distance()¶
Get the distance to the control nearest the finish and back again.
- Return type:
int
- Returns:
Distance running to the nearest control and back to finish.
- read_ocad_course_file(filename)¶
Reads an OCAD file and prints information about controls.
- Return type:
None
- Parameters:
filename (Path)
- read_score_file(filename)¶
Reads a score file with the score of each control.
Format: control_id, score Only scores from controls matching the control keys from the imported OCAD-file will be imported.
- Parameters:
filename (
Path
) – Name of the score file- Return type:
None
- set_terrain_coordinates()¶
Set terrain coordinates in meters, using an offset to get positive numbers.
- Return type:
None
- solution_length(solution)¶
Calculate the length of a given solution.
The length includes the distance back to start/finish.
- Parameters:
solution (
list
[int
]) – A list of control numbers representing the solution.- Return type:
int
- Returns:
The length of the solution.
- solution_score(solution)¶
Calculate the total score of a given solution.
- Parameters:
solution (
list
[int
]) – A list of control numbers representing the solution.- Return type:
int
- Returns:
The total score of the solution.
- write_opsolver_file(source_file, distance_limit)¶
Write a problem file in oplib format for opsolver.
The file format is described on https://github.com/bcamath-ds/OPLib/tree/master/instances
- Parameters:
source_file (
Path
) – IOF xml file with control coordinates.distance_limit (
int
) – The distance limit for the problem, in meters.
- Return type:
Path
- Returns:
The filename and path of the generated opsolver file.
- Raises:
ValueError – If missing control for code.
- write_score_template(filename)¶
Write a template file for setting scores on each control.
- Return type:
None
- Parameters:
filename (Path)
scoreo.opsolver module¶
Module for running opsolver in docker image.
- find_all_solutions(problem_file, start_distance, stop_distance, heuristic=False)¶
Find all solutions shorter than the distance limit.
Start at distance limit and generate solutions iteratively with shorter limits.
- Parameters:
problem_file (
Path
) – The file describing the problem to solve.start_distance (
int
) – The distance limit for the problem, in meters.stop_distance (
int
) – Finish the search when this distance is reached.heuristic (
bool
) – Whether to use heuristic algorithm or not. Defaults to False.
- Return type:
list
[Solution
]- Returns:
A list of solutions.
- find_initial_solution(problem_file)¶
Find initial solution covering all controls.
Guess an initial distance limit and iterate until the shortest cycle covering all controls is found.
- Parameters:
problem_file (
Path
) – The file describing the problem to solve.- Return type:
- Returns:
The initial solution.
- run_opsolver(problem_file, heuristic=False)¶
Run opsolver on the given problem file.
- Parameters:
problem_file (
Path
) – The file describing the problem to solve.heuristic (
bool
) – Whether to use heuristic algorithm or not. Defaults to False.
- Return type:
- Returns:
The solution to the problem.
- update_distance_limit(problem_file, distance_limit)¶
Update the distance limit in the problem file with the new limit.
- Parameters:
problem_file (
Path
) – The file describing the problem to solve.distance_limit (
int
) – The distance limit for the problem, in meters.
- Return type:
None
scoreo.solution module¶
Functions for working with the solutions from opsolver.
- class Solution(score, number_of_controls, distance, controls, distance_limit, problem_number_of_controls)¶
Bases:
object
Class for storing information about a solution.
- Parameters:
score (int)
number_of_controls (int)
distance (int)
controls (list[int])
distance_limit (int)
problem_number_of_controls (int)
-
controls:
list
[int
]¶
-
distance:
int
¶
-
distance_limit:
int
¶
-
number_of_controls:
int
¶
-
problem_number_of_controls:
int
¶
-
score:
int
¶