-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Contours ADT Module in GlassBR as per issue #134
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
CaseStudies/glass/src/Python/NewImplementation/ContoursADT.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
## @file ContoursADT.py | ||
# @brief Implements an ADT for a contour | ||
# @date 07/26/2018 | ||
|
||
from Exceptions import * | ||
from FunctADT import FuncT | ||
|
||
class ContoursT : | ||
|
||
# exported constants | ||
MAX_ORDER = 2 | ||
|
||
def __init__ ( self, i ): | ||
|
||
if (not(i in list(range(1, self.MAX_ORDER + 1)))): | ||
raise InvalidInterpOrder("Invalid interpretation error!") | ||
|
||
# state variables | ||
self.S = [] | ||
self.Z = [] | ||
self.o = i | ||
|
||
## @brief Appends elements to state variable sequences | ||
def add( self, s, z): | ||
if ((len(self.Z)) > 0) and (z <= self.Z[len(self.Z) - 1]): | ||
raise IndepVarNotAscending("Independent variables not in ascending order!") | ||
self.S = self.S.append(s) | ||
self.Z = self.Z.append(z) | ||
|
||
## @brief Gets the ith element from the sequence S | ||
# @return the ith element from S | ||
def getC( self, i): | ||
if (not(0 <= i <= len(self.S))): | ||
raise InvalidIndex("Index out of range") | ||
return self.S[i] | ||
|
||
## @brief Evaluates the FuncT class with respect to input z | ||
# @return the calculated FuncT class based on z | ||
def eval( self, x, z): | ||
return (self.slice(x,False).eval(z)) | ||
|
||
## @brief Evaluates the FuncT class with respect to input y | ||
# @return the calculated FuncT class based on y | ||
def evaly( self, x, y): | ||
return (self.slice(x,True).eval(y)) | ||
|
||
## @brief Generates a FuncT class using the state variable sequences | ||
# @return the generated FuncT class | ||
def slice( self, c, flip): | ||
Zdef = [] | ||
F = [] | ||
for i in range(0,(len(self.S)) - 1): | ||
try: | ||
y = self.S[i].eval(x) | ||
Zdef.append(self.Z[i]) | ||
F.append(y) | ||
except OutOfDomain: | ||
pass | ||
if (len(Zdef)) > 0: | ||
if flip: | ||
return FuncT(F, Zdef, o) | ||
else: | ||
return FuncT(Zdef, F, o) | ||
else: | ||
raise OutOfDomain("Out of domain!") |