Commit 6d1dd8d8 authored by Navid Mokhlesi's avatar Navid Mokhlesi
Browse files

added comments to function headers

parent 1ed69c48
......@@ -12,7 +12,7 @@ parser.add_argument('-f', type=str, default='output/reachtube.txt', help='file p
parser.add_argument('-l', type=str, default='output/reachtube_symlabel.txt', help='file path for reach tube symmetry labels')
parser.add_argument('-y', type=str, default='[1]', help='dimension number you want to plot, ex [1,2], default first dimension')
parser.add_argument('-y', type=str, default='[1,2]', help='dimension number you want to plot, ex [1,2] (default)')
parser.add_argument('-x', type=str, default='0', help='dimension number you want to plot, ex 0, default time')
parser.add_argument('-o', type=str, default='plotResult.png', help='output file name')
args = parser.parse_args()
......@@ -49,6 +49,7 @@ xdim = eval(args.x)
plot3d(mode_name, ydim, bounds, xdim, tube_sym_labels)
"""
# We do not currently support hybrid systems directly with symmetries
while stack:
curNode = stack.pop()
for c in curNode.child:
......
......@@ -8,7 +8,7 @@ class TreeNode:
:param initial_set: initial set is a polytope from Library (no time)
:param reachtube: tube 2dlist in tube format from reachtube.py (has time)
:param traces: list of points from all simulations (3d list) (has time
:param parent reference in binary tree.
Each node stores initial set as polytope without time,
"""
......@@ -32,7 +32,8 @@ class TreeNode:
print "A node with height ",self.height," has been added to the tree"
# this class contains a reference to the root of a cache tree, and in the future could contain a
# cleaner Datastructure interface
class CacheTree:
def __init__(self, root=None):
......
......@@ -11,16 +11,21 @@ import polytope as pc
import ast
import numpy as np
"""Takes a String s and Character ch
Returns a list of all the indices where """
def find_ch(s, ch):
return [i for i, ltr in enumerate(s) if ltr == ch]
"""
Converts inequality to a single constraint of a polytope's H-representation
"""
def parse_ineq(s, num_vars, varIdx):
tree = ast.parse(s)
visitor = Vis_dfs(num_vars, varIdx)
visitor.visit(tree)
return visitor.row, visitor.b_row
d
class Vis_dfs(ast.NodeVisitor):
def __init__(self, n, varIdx):
self.row = np.zeros(n) # the plus one is for the time variable
......@@ -349,7 +354,9 @@ class Guard():
return None, tube, tube[-1][0]
"""
Takes a list of inequalities and builds a polytope's H-representation out of it.
"""
def parse_ineq_list(cond_str, num_vars, varIdx):
# TO BE BUILT
s = ""
......@@ -384,4 +391,3 @@ def parse_ineq_list(cond_str, num_vars, varIdx):
# print "A: ", A
# print "b: ", b
return A, b
......@@ -12,6 +12,9 @@ class Transform:
def __init__(self, inp, n, is_matrix=False, is_permutation=False):
"""
:param inp: Linear Transformation Matrix or Translation Vector
:param n: number of dimensions in our system
:param is_matrix: determines if inp is a transformation Matrix or not
:param is_permutation: determines if inp is a list of pairs of permutable dimensions or a translation vector/Matrix
returns transform object!
"""
assert inp is not None, "Input is broken"
......@@ -47,6 +50,11 @@ class Transform:
def get_gamma(self, initial_set_c, initial_set_u):
"""
:param initial_set_c: initial set we are hoping to translate initial_set_u over
:param initial_set_u: initial set we are hoping to translate over initial_set_c
:return: translation vector between two inital sets after projecting away their translation invariant dimensions
"""
translation_dest = self.trans_inv_proj(np.array(initial_set_u.b[0:self.n]) / 2.0 - np.array(initial_set_u.b[self.n:2*self.n]) / 2.0)
translation_src = self.trans_inv_proj(np.array(initial_set_c.b[0:self.n]) / 2.0 - np.array(initial_set_c.b[self.n:2*self.n]) / 2.0)
self.translation_vec[1:] = translation_dest - translation_src
......@@ -82,6 +90,12 @@ class Transform:
return vertex + self.translation_vec[1:]
def transform_vertices(self, points):
"""
Args: self: linear transformation information stored as transformation object.
vector: length n vector, the coordinate of the point we are going to transform
returns:
transformed Polytope from polytope library
"""
assert len(points) > 0, "no points given!"
points = np.array(points)
if self.is_matrix:
......@@ -108,10 +122,9 @@ class Transform:
def trans_inv_proj(self, point):
"""
:param self: transform Object
:param self: transform Object containing transformation configuration
:param point: takes in a point without time as 1d numpy array
:return:
:return: reduces the dimensionality of a coordinate to exclude the translation invariant dimensions.
"""
assert (not self.is_matrix) and (not self.is_perm), "whoa there"
point = np.array(point)
......@@ -225,7 +238,7 @@ class Transform:
Args: self: linear transformation matrix stored in transformation object
reg: Region object from polytope library
returns:
transformed polytope from polytope library
transformed Region from polytope library
"""
return pc.Region(list_poly=map(lambda x: self.transform_poly(x), reg.list_poly))
#if reg.dim == self.n + 1:
......@@ -235,9 +248,23 @@ class Transform:
def transform_region_list(self, list_reg):
"""
Args: self: linear transformation matrix stored in transformation object
list_reg: list of Region objects from polytope library
returns:
transformed list of Regions from polytope library
This list of regions is stored in chronological order
and represents a reachtube usually.
"""
return map(lambda x: self.transform_region(x), list_reg)
def rect_poly_project(self,poly,dim, poly_has_time=False):
"""
:param poly: reduces dimensionality of polytope according to dim param
:param dim: specifies constraints to remove by dimension index
:param poly_has_time: boolean for if the provided polytope has a time dimension
:return:
"""
poly = self.correct_rows_order(poly)
A = poly.A
b = poly.b
......@@ -272,7 +299,14 @@ class Transform:
return p
def region_projection(self,reg, dim, reg_has_time=False):
"""
:param poly: reduces dimensionality of polytope according to dim param
:param dim: specifies constraints to remove by dimension index
:param poly_has_time: boolean for if the provided polytope has a time dimension
:return: reduced dimensionality polytope
"""
proj_reg = pc.Region(list_poly=[])
# print "list poly:", reg.list_poly
# for i in range(len(reg.list_poly)):
......@@ -291,6 +325,10 @@ class Transform:
return proj_reg
def correct_rows_order(self,poly):
"""
:param poly: given a polytope from polytope library
:return: returns a polytope from polytope library with same A matrix row ordering as from box2poly
"""
offset = 0
for i in range(poly.A.shape[0]):
for j in range(poly.A.shape[1]):
......@@ -314,6 +352,11 @@ class Transform:
return poly
def rect_poly_permutation(self, poly, poly_has_time=False):
"""
:param poly: polytope from polytope library
:param poly_has_time: boolean for if polytope has time dimensions as 1st index
:return: polytope from polytope library with permuted dimensions result from swap_vars.
"""
b = poly.b
A = poly.A
for row1, row2 in self.swap_vars:
......@@ -325,7 +368,7 @@ class Transform:
A[:, row2] = tmp
return pc.Polytope(A=A, b=b)
# Enum for return values of symmetry algorithm 2
class SymReturn(Enum):
SAFE = 0
UNSAFE = 1
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment