Util Module

Copyright (C) 2011-2017 Philip Axer, Jonas Diemer
TU Braunschweig, Germany
All rights reserved.
See LICENSE file for copyright and license details.
Authors:
  • Philip Axer
  • Jonas Diemer

Description

Various utility functions

pycpa.util.GCD(terms)[source]

Return gcd of a list of numbers.

pycpa.util.LCM(terms)[source]

Return lcm of a list of numbers.

pycpa.util.additive_extension(additive_func, q, q_max, cache=None, cache_offset=1)[source]

Additive extension for event models. Any sub- or super- additive function additive_func valid in the domain q in [0, q_max] is extended and the approximited value f(q) is returned. NOTE: this cannot be directly used with delta curves, since they are “1-off”, thus if you supply a delta function to additive_func, note to add 1 and supply q-1. e.g. util.additive_extension(lambda x: self.delta_min(x + 1), n - 1, q_max)

pycpa.util.bitrate_str_to_bits_per_second(bitrate_str)[source]

Convert bitrate strings like “100MBit/s” or “1 Gbit/s” to an integer representation in Bit/s.

returns a set of nodes (tasks) which is reachable starting from the starting task. calls func on the first discover of a task.

get_reachable_tasks(task) specifies a function which returns all tasks considered immediately reachable for a given task.

pycpa.util.combinations_with_replacement(iterable, r)[source]

combinations_with_replacement(‘ABC’, 2) –> AA AB AC BB BC CC

pycpa.util.cycles_to_time(value, freq, base_time, rounding='ceil')[source]

Converts the cycle/bittimes to an absolute time in base_time

pycpa.util.dijkstra(source)[source]

Calculates a distance-map from the source node based on the dijkstra algorithm The edge weight is 1 for all linked tasks

pycpa.util.gcd(a, b)[source]

Return greatest common divisor using Euclid’s Algorithm.

pycpa.util.generate_distance_map(system)[source]

Precomputes a distance-map for all tasks in the system.

pycpa.util.get_next_tasks(task)[source]

return the list of next tasks for task object. required for _breadth_first_search

pycpa.util.get_path(t_src, t_dst)[source]

Find path between tasks t_src and t_dst. Returns a path as list() or None if no path was found. NOTE: There is no protection against cycles!

pycpa.util.lcm(a, b)[source]

Return lowest common multiple.

pycpa.util.recursive_max_additive(additive_func, q, q_max, cache=None, cache_offset=1)[source]

Sub-additive extension for event models. Any sub-additive function additive_func valid in the domain q in [0, q_max] is extended and the value f(q) is returned. It is optional to supply a cache dictionary for speedup.

NOTE: this cannot be directly used with delta curves, since they are “1-off”, thus if you supply a delta function to additive_func, note to add 1 and supply q-1. e.g. ret = util.recursive_max_additive(lambda x: self.delta_min(x + 1), n - 1, q_max, self.delta_min_cache)

By default, the cache is filled according to the delta domain notion, so it can be used with delta-based event models. To override this behavior, change the cache_offset parameter to zero

pycpa.util.recursive_min_additive(additive_func, q, q_max, cache=None, cache_offset=1)[source]

Super-additive extension for event models. Any additive function additive_func valid in the domain q in [0, q_max] is extended and the value f(q) is returned. It is optional to supply a cache dictionary for speedup.

NOTE: this cannot be directly used with delta curves, since they are “1-off”, thus if you supply a delta function to additive_func, note to add 1 and supply q-1. e.g. ret = util.recursive_min_additive(lambda x: self.delta_plus(x + 1), n - 1, q_max, self.delta_plus_cache)

By default, the cache is filled according to the delta domain notion, so it can be used with delta-based event models. To override this behavior, change the cache_offset parameter to zero

pycpa.util.str_to_time_base(unit)[source]

Return the time base for the string

pycpa.util.time_base_to_str(t)[source]

Return the time base for the string

pycpa.util.time_str_to_time(time_str, base_out, rounding='ceil')[source]

Convert strings like “100us” or “10 ns” to an integer representation in base_out.

pycpa.util.time_to_cycles(value, freq, base_time, rounding='ceil')[source]

Converts an absolute time given in the base_time domain into cycles

pycpa.util.time_to_time(value, base_in, base_out, rounding='ceil')[source]

Convert an absolute time given in base_in to another absolute time given in base_out

pycpa.util.uunifast(num_tasks, utilization)[source]

Returns a list of random utilizations, one per task [0.1, 0.23, …] WCET and event model (i.e. PJd) must be calculated in a second step)

pycpa.util.window(seq, n=2)[source]

Returns a sliding window (of width n) over data from the iterable s -> (s0,s1,…s[n-1]), (s1,s2,…,sn), …