Exemplo n.º 1
0
 def __init__(self, BondsList = [], ElementsList = [], \
              graph = Graph(), Name = None):
     """ initializes a BGcomponent object """
     BGcomponent.__init__(self)
     Graph.__init__(self)
     self.id = next(self.id_generator)
     self.__id = BondGraph.__ID
     BondGraph.__ID += 1
     self.__id += 1
     self.__bondsList = BondsList
     self.__elementsList = ElementsList
     self.__name = Name
Exemplo n.º 2
0
 def __init__(self, fromPort = 0, toPort = 0, Type = 'PowerBond'):
     """ initializes a BGcomponent object """
     BGcomponent.__init__(self)
     Graph.__init__(self)
     self.id = next(self.id_generator)
     self.__id = BGbond.__ID
     BGbond.__ID += 1
     self.__id += 1
     self.__fromPort = fromPort
     self.__toPort = toPort
     self.__causalityStroke = 1
     self.__directionArrow = 1
     self.__type = Type
Exemplo n.º 3
0
 def __init__(self, Name = None, Type = None, Position = [0,0]):
     """ initializes a BGcomponent object """
     BGcomponent.__init__(self)
     Graph.__init__(self)
     self.id = next(self.id_generator)
     self.__id = BGelement.__ID
     BGelement.__ID += 1
     self.__id += 1
     self.__type = Type
     self.__name = Name
     self.__position = Position
     self.variable = None
     self.stateEquation = None
     self.outputEquation = None
     self.modulus = None
     self.common = None
Exemplo n.º 4
0
 def draw(self):
     if not self.edges:
         if self.validate(self.inputEntry.get()):
             if not self.edges:
                 self.graphCanvas.delete("all")
                 self.outputText.set(
                     "There isn't any input.\nPlease, Enter a edges array.")
                 showerror(
                     "No Input",
                     "There isn't any input.\nPlease, Enter a edges array.")
             else:
                 self.draw()
     else:
         edges = self.edges
         if edges != -1:
             self.graph = Graph(self.edges)
             self.edges = np.copy(self.graph.edges)
             self.graphCanvas.delete("all")
             self.canvasItems = drawGraphtoCanvas(self.graphCanvas,
                                                  self.edges,
                                                  self.graph.vertex_n,
                                                  self.canvasSize)
             # print self.canvasItems
             for item in range(self.graph.vertex_n):
                 self.startPoints.insert(END, item)
         else:
             graphCheck = "ERROR : edges -1 There isn't a graph."
             mbox.showerror('No Graph', graphCheck)
Exemplo n.º 5
0
 def openFile(self):
     fileName = tkfd.askopenfilename()
     if fileName != '' :
         inStr ,self.edges = takeFileInput(fileName)
         self.outputText.set("Read input:\n"+inStr)
         self.graph = Graph(self.edges)
         self.inputEntry.insert(0, '')
     else:
         self.outputText.set("There isn't any input.\nPlease, choose a file.")
         mbox.showerror("No Input", "There isn't any input.\nPlease, choose a file.")
Exemplo n.º 6
0
 def validate(self, text):
     if text == '':
         self.outputText.set("There isn't any input.\nPlease, Enter a edge array.")
         self.inputEntry.insert(0, '')
         return False
     try:
         self.edges = takeInstInput(text)
         print ("edges: ",self.edges)
         if self.edges != []:
             self.graph = Graph(self.edges)
             return True
     except ValueError:
         self.outputText.set("Wrong input format")
         mbox.showerror("Wrong Format", "Wrong input format")
         return False
Exemplo n.º 7
0
 def compute(self):
     if self.edges == []:
         self.draw()
         if self.edges != []:
             self.compute()
     else:
         edges = self.edges
         if edges != []:
             # calculating the mst with prim algorithm
             prim, keys = mst_prim(self.graph, self.startV)
             self.mst_g = Graph(mst_to_edges(prim, keys))
             self.find_changes()
             self.changeToggle = np.zeros(self.stepCnt)
             self.inputEntry.delete(0, END)
             self.edges = []
             self.startPoints.delete(0, END)
         else:
             graphCheck = "ERROR : edges is empty There isn't a graph."
             mbox.showerror('No Graph', graphCheck)
Exemplo n.º 8
0
 def compute(self):
     if not self.edges:
         if self.validate(self.inputEntry.get()):
             if not self.edges:
                 self.graphCanvas.delete("all")
                 self.outputText.set("There isn't any input.\nPlease, Enter a edges array.")
                 showerror("No Input", "There isn't any input.\nPlease, Enter a edges array.")
             else:
                 self.compute()
     else:
         node = self.graph.vertex_n # meaningless
         edges = self.edges
         if edges != -1:
             self.graphCanvas.delete("all")
             self.canvasItems = drawGraphtoCanvas(self.graphCanvas, edges, node, self.canvasSize)
             # print self.canvasItems
             self.mst_g = Graph(mst_kruskal(self.graph))
             self.find_changes()
             self.changeToggle = np.zeros(self.stepCnt)
             self.inputEntry.delete(0, END)
             self.edges = []
         else:
             graphCheck = "ERROR : edges -1 There isn't a graph."
             mbox.showerror('No Graph', graphCheck)
Exemplo n.º 9
0
# Build data structures to store semantic vectors globally for determining kNN
# Note: all vectors are converted to "utf-8". L1 vectors are converted to lower case
#       L2 vectors are converted to upper case
# Note: must create another list of just concept names (no tuples)
def removeTuples(tuples_list):
    no_tuples = []
    for el in tuples_list:
        no_tuples.append(el[0])
    return no_tuples

evoked_en, evoking_en = loadVectors_unicode(removeTuples(concepts_en), eng_vectors,L1=True)     # English lexicon
evoked_sp, evoking_sp = loadVectors_unicode(concepts_sp, span_vectors,L1=False)    # Spanish lexicon

# Initialize graph
g = Graph()

# Create vertices from the concepts store in running list of the all existing Vertices in the graph
all_vertices = g.store_vertices(concepts_en)
g.add_vertices(all_vertices)

#   ************************************************************************************************
#   *                                  FUNCTIONS TO BUILD GRAPH                                    *
#   ************************************************************************************************

#   PURPOSE: Translate a given English word to its Spanish equivalent
#   PARAMETERS: Concept in English (string)
#   RETURNS: Concept in Spanish (utf-8 format, upper case)
def en2sp(concept):
    # for non-Google translate
    # translator = Translator(provider='microsoft', from_lang='en', to_lang='es', secret_access_key=secret)
    def load_graph(self):
        # Initiate the disciplines collection
        database = Connection.connectionDatabase()
        collectionDiscipline = database['disciplines']

        # load the list of disciplines, node and edges for graph
        list_disciplines = []
        nodes = []
        edges = []
        discipline_relation = {}

        # Load the disciplines of the habilitaion
        # from all peorids and
        # join all in a unique list
        for discipline in self.code['disciplines']:
            list_disciplines += discipline.values()[0]

        # print(len(list_disciplines))
        # Run in all list disicplines code and search for it in database
        # Add it in node  list with name and code
        # And all the requirement belong it is add in edges from graph connect
        for discipline in list_disciplines:

            current_dis = collectionDiscipline.find_one(
                {'code': str(discipline)})

            if current_dis is None:
                nodes.append((str(discipline), str(discipline)))
                continue

            requirements = self.convert_requirements(
                current_dis['requirements'])
            code = str(discipline)
            label = current_dis['name']

            nodes.append((code, label))
            discipline_relation[code] = []

            for index, requirement in enumerate(requirements):

                if isinstance(requirement, list):

                    and_node_name = self.get_and_name(code, index)
                    nodes.append((and_node_name, 'E'))
                    edges.append((and_node_name, code))

                    for req in requirement:
                        edges.append((str(req), and_node_name))
                        discipline_relation[code].append(str(req))

                else:
                    edges.append((str(requirement), code))
                    discipline_relation[code].append(str(requirement))

        print(discipline_relation)

        # Graph(discipline_relation).dfs_recursao()
        Graph(discipline_relation).topologicalSort()

        # create a direct graph horizontal
        graph = ptp.Dot(graph_type='digraph', rankdir='LR')

        # Adding all edges and nodes in instace of graph
        for e in edges:
            graph.add_edge(ptp.Edge(e[0], e[1]))
        for n in nodes:
            node = ptp.Node(name=n[0], label=n[1], style="filled")
            graph.add_node(node)

        # create an png image from the result
        graph.write_png('graph.png')
Exemplo n.º 11
0
from graphClass import Graph
from fileClass import FileWriter
from pointClass import *
from sqlClass import SQL

fileWriter=FileWriter()
pointArray=PointArray()
graph=Graph()
sql=SQL()

# stream=fileWriter.getProcessedStreamArrayFromArray(arr)
stream=fileWriter.getProcessedStreamArrayFromUnprocessedFile("samplefile.csv")
pointArray.populateWithStream(stream)
pointArray.printTimeArrCood()
graph.setPointArray(pointArray)
graph.plotTimeGraph()
graph.plotFFTGraph()
graph.showGraphs()
Exemplo n.º 12
0
    def load_graph(self):
        # Initiate the disciplines collection
        database = Connection.connectionDatabase()
        collectionDiscipline = database['disciplines']

        # load the list of disciplines, node and edges for graph
        list_disciplines = []
        nodes = []
        edges = []
        discipline_relation = {}

        # Load the disciplines of the habilitaion
        # from all peorids and
        # join all in a unique list
        for discipline in self.code['disciplines']:
            list_disciplines += discipline.values()[0]

        # print(len(list_disciplines))
        # Run in all list disicplines code and search for it in database
        # Add it in node  list with name and code
        # And all the requirement belong it is add in edges from graph connect
        for discipline in list_disciplines:
            current_dis = collectionDiscipline.find_one({'code': discipline})
            # print(current_dis)
            if current_dis != None:

                type_str = False

                if len(current_dis['requirements']) > 1:
                    type_str = True
                else:
                    nodes.append((int(discipline), current_dis['name']))

                cont = 1
                for requirement in current_dis['requirements']:
                    # print(requirement)

                    if type_str:
                        nodes.append((str(discipline) + str(cont), 'E'))
                        edges.append(
                            (str(discipline) + str(cont), int(discipline)))

                    if isinstance(requirement, list):
                        if cont == 1:
                            discipline_relation[
                                current_dis['code']] = requirement

                        for single_requirement in requirement:
                            if type_str:
                                edges.append((int(single_requirement),
                                              str(discipline) + str(cont)))
                            else:
                                edges.append(
                                    (int(single_requirement), int(discipline)))
                    else:
                        if cont == 1:
                            discipline_relation[current_dis['code']] = list(
                                requirement)

                        edges.append((int(requirement), int(discipline)))
                    cont += 1
            else:
                nodes.append((int(discipline), str(discipline)))

        print(discipline_relation)

        # Graph(discipline_relation).dfs_recursao()
        Graph(discipline_relation).topologicalSort()

        # create a direct graph horizontal
        graph = ptp.Dot(graph_type='digraph', rankdir='LR')

        # Adding all edges and nodes in instace of graph
        for e in edges:
            graph.add_edge(ptp.Edge(e[0], e[1]))
        for n in nodes:
            node = ptp.Node(name=n[0], label=n[1], style="filled")
            graph.add_node(node)

        # create an png image from the result
        graph.write_png('graph.png')
Exemplo n.º 13
0
from graphClass import Graph
from nodeDict import nodeDict

#------------------------- Functionality Functions -------------------------
G = Graph()


def textToGraph():
    fname = input("What file do you want to use?")
    readData, num_lines = nodeDict(fname)
    #print(readData)
    for i in readData.keys():
        origin = G.insert_vertex(i)
    for i in readData.keys():
        for j in readData[i]:
            origin = G.insert_vertex(i)
            dest = G.insert_vertex(j)
            e = G.insert_edge(origin, dest)
            #if e == None:
            #  e = G.insert_edge(dest, origin)
            #print(origin.cityName(),e.opposite(origin).cityName())
    return G, num_lines


def printGraph(a_Graph):
    for vertices in a_Graph._cities:
        name, val = vertices.cityName(), vertices.get_val()
        print("Node: {0}, Name: {1}".format(val, name))
        currentCityLinkedList = a_Graph._cities[vertices]
        currentEdge = currentCityLinkedList.get_head_value()
        while currentEdge: