API Documentation

kiacopy package

kiacopy.solver module

class kiacopy.solver.Solver(rho=0.03, q=1, gamma=1, theta=2, inf=1e+100, sd_base=1e+20, top=None, plugins=None)[source]

Bases: object

add_plugin(plugin)[source]
add_plugins(*plugins)[source]
find_solution(graph, ants, is_res)[source]
get_plugins()[source]
opt2(graph, solution, origin)[source]
optimize(graph, colony, gen_size=None, limit=None, problem=None, is_update=False, is_best_opt=False, is_res=False, graph_name='')[source]
pheromone_update(solution, state, graph)[source]
solve(*args, **kwargs)[source]

kiacopy.colony module

class kiacopy.colony.Colony(alpha=1, beta=3, random=0, sensitive=0, q_0=0.2, tau_0=0.01, rho=0.03)[source]

Bases: object

get_ants(count)[source]

kiacopy.solution module

class kiacopy.solution.Solution(gamma, theta, inf, sd_base)[source]

Bases: list

avg
cost
sd
sum

kiacopy.circuit module

class kiacopy.circuit.Circuit(graph, start, ant=None)[source]

Bases: object

add_node(node)[source]

Record a node as visited.

Parameters:node – the node visited
close()[source]

Close the tour so that the first and last nodes are the same.

get_easy_id(sep=' ', monospace=True)[source]
get_id()[source]
reconstruct()[source]
trace(q, rho=0)[source]

kiacopy.state module

kiacopy.utils package

kiacopy.utils.data module

kiacopy.utils.data.get_demo_graph()[source]
kiacopy.utils.data.get_formats()[source]
kiacopy.utils.data.read_graph_data(path, format_)[source]
kiacopy.utils.data.read_json(path)[source]
kiacopy.utils.data.read_tsplib95(path)[source]

kiacopy.utils.general module

kiacopy.utils.general.is_plot_enabled()[source]

Return true if plotting is enabled.

Plotting requires matplotlib and pandas to be installed.

Returns:indication of whether plotting is enabled
Return type:bool
kiacopy.utils.general.looper(limit)[source]

Return an optionally endless list of indexes.

kiacopy.utils.general.positive(value)[source]

kiacopy.utils.plot module

The plot utility works with the StatsRecorder plugin to generate interesting plots of solver iterations.

class kiacopy.utils.plot.Plotter(stats)[source]

Bases: object

Utility for plotting iteration data using matplotlib.

This is meant to be used in combination with the StatsRecorder plugin which collects stats about solutions and pheromone levels on each iteration.

Parameters:stats (dict) – map of stats by name
extract_ant_distances()[source]
plot(is_level=True)[source]

Create and show the plot.

save(save_path='.', leading='', is_level=True)[source]

Create and save the plot.

kiacopy.ants package

kiacopy.ants.ant module

class kiacopy.ants.ant.Ant(alpha=1, beta=3, **kwargs)[source]

Bases: object

alpha
beta
choose_destination(graph)[source]
choose_node(scores)[source]
erase(graph, now, to)[source]
get_scores(graph)[source]
init_solution(graph, inf, is_res, theta, start=1)[source]
init_unvisited_nodes(graph)[source]
move(graph)[source]
score_edge(edge)[source]
score_residual(graph, to)[source]

kiacopy.ants.sensitiveant module

class kiacopy.ants.sensitiveant.SensitiveAnt(alpha=1, beta=3, q_0=0.2)[source]

Bases: kiacopy.ants.ant.Ant

choose_node(scores)[source]

kiacopy.ants.randomant module

class kiacopy.ants.randomant.RandomAnt(alpha=1, beta=3, q_0=0.2)[source]

Bases: kiacopy.ants.ant.Ant

choose_node(scores)[source]