def system_test_bench_sim(no_inputs, input_bitwidth, no_outputs,
                          output_bitwidth):
    clk = Signal(bool(False))
    enable = Signal(bool(False))
    reset = Signal(bool(False))
    data_correct = Signal(bool(False))

    arc = Arc.Arc(reset, no_inputs, input_bitwidth, no_outputs,
                  output_bitwidth, False, 1)
    test_data = [int(random.random() * 255) - 128 for i in range(no_inputs)]

    @always(delay(1))
    def clock():
        clk.next = not (clk)

    @instance
    def actor_enable():
        yield delay(1)
        enable.next = True
        yield delay(1)

    @always(data_correct.posedge)
    def data_correct_check():
        print "Data Correct Signal Detected!"

    system_test_bench_inst = system_test_bench(clk, enable, reset,
                                               data_correct, arc, test_data)

    return instances()
    def checkAndUpdateGraph(self, fPerson, sPerson, debt):
        fPresent = 0
        sPresent = 0
        i = 0
        oldDebt = None
        while (not fPresent or not sPresent) and i < len(self.__nodesNames):
            if not fPresent and fPerson == self.__nodesNames[i].getName():
                fPresent = 1
                nodeF = self.__nodesNames[i]
            if not sPresent and sPerson == self.__nodesNames[i].getName():
                sPresent = 1
                nodeS = self.__nodesNames[i]
            i += 1
        if not fPresent:
            nodeF = Node(fPerson, len(self.__nodesNames))
            self.__nodesNames.append(nodeF)
        if not sPresent:
            nodeS = Node(sPerson, len(self.__nodesNames))
            self.__nodesNames.append(nodeS)

        if fPresent and sPresent:
            oldDebt = debt
            debt = self.checkAndSuppressMutualDebt(nodeS, nodeF, debt)
        newArc = Arc(nodeS, debt, oldDebt)
        nodeF.addArc(newArc)
Esempio n. 3
0
def main():
    win = GraphWin("My Circle", 500, 500)
    c = Circle(Point(250, 250), 100)
    c.draw(win)
    c.setOutline('black')
    c.setFill('yellow')
    c1 = Circle(Point(200, 230), 25)
    c2 = Circle(Point(300, 230), 25)
    c1.setOutline('black')
    c1.setFill('white')
    c2.setOutline('black')
    c2.setFill('white')
    c1.draw(win)
    c2.draw(win)
    mouth = Oval(Point(200, 270), Point(300, 300))
    mouth.setFill("red")
    #mouth.draw(win)
    c12 = Circle(Point(200, 230), 15)
    c22 = Circle(Point(300, 230), 15)
    c12.setFill('black')
    c22.setFill('black')
    c12.draw(win)
    c22.draw(win)
    arc = Arc(Point(220, 300), Point(280, 280), -180)
    arc.setFill("red")
    arc.draw(win)
Esempio n. 4
0
 def generationArcs(self):
     arretsAvs = list()
     arretsAps = list()
     poid = list()
     for i in range(len(self.listArrets) - 1):
         arretsAvs.append(self.listArrets[i])
         arretsAps.append(self.listArrets[i + 1])
         poid.append(
             self.defPoidArcs(self.listArrets[i], self.listArrets[i + 1]))
         self.listArcs.append(Arc(arretsAvs, arretsAps, poid))
         #            print("Arc : ")
         #            for j in range(len(arretsAvs)):
         #                print("Arrets Avants : ", self.listArcs[i].arretsAvs[j].label)
         #            print("-->")
         #            for k in range(len(arretsAps)):
         #                print("Arrets Apres : ", self.listArcs[i].arretsAps[j].label,"\n")
         arretsAps = list()
         arretsAvs = list()
         poid = list()
Esempio n. 5
0
    def readGraph(self, filename, numberOfNodes):
        """
        This method reads the file and creates the graph, storing it in a matrix
        :param filename: name of the file that will be open
        :param numberOfNodes: number of node that will be read
        :return: None
        """

        self.__numberNodes = numberOfNodes
        latSum = 0.0
        lonSum = 0.0
        try:
            file = open(filename, "r", encoding='utf-8')
            strP = file.readline().split(" ")[1]

            try:
                self.__p = int(strP)
                self.__mode = 1
            except ValueError:
                self.__p = float(strP)
                self.__mode = 0

            for i in range(4):
                line = file.readline()

            cont = 0

            while line != "" and line != "\n":
                cont += 1

                if len(line) > 0 and line != "\n":

                    if "Costo" in line:
                        break

                    description = ""
                    lineArray = line.split(" ")

                    if len(lineArray) >= 4:
                        description = lineArray[3]

                    node = Node(int(lineArray[0]), float(lineArray[1]),
                                float(lineArray[2]), description)
                    lonSum += float(lineArray[1])
                    latSum += float(lineArray[2])

                    self.__graph[node.getID()] = node
                    self.__nodesArray.append(node)
                    self.__lonArray.append(float(lineArray[1]))
                    self.__latArray.append(float(lineArray[2]))

                line = file.readline()

            self.__promLon = lonSum / numberOfNodes
            self.__promLat = latSum / numberOfNodes

            self.__distanceLongi = self.getDistanceBetweenLongitudesG(
                self.__promLat)

            for i in range(3):
                line = file.readline()

            self.__matrix = [[
                Arc(0, 0, None, None) for x in range(numberOfNodes)
            ] for y in range(numberOfNodes)]

            while line != "" and line != "\n":

                if len(line) > 0:
                    lineArray = line.split(" ")
                    node1 = self.__graph.get(int(lineArray[0]))
                    node2 = self.__graph.get(int(lineArray[1]))
                    arc = Arc(lineArray[2],
                              self.getDistanceBNodes(node1,
                                                     node2), node1, node2)
                    self.__matrix[int(lineArray[0]) - 1][int(lineArray[1]) -
                                                         1] = arc

                line = file.readline()

            file.close()
            for node in self.__nodesArray:
                arc = Arc(0, 0, node, node)
                self.__matrix[int(node.getID()) - 1][int(node.getID()) -
                                                     1] = arc

        except:
            print("An error occurred while reading the file")

        self.__targetLat = self.__matrix[0][0].getNodeFrom().getLatitude()
        self.__targetLon = self.__matrix[0][0].getNodeFrom().getLongitude()
Esempio n. 6
0
for td in range(max(no_outputs,no_inputs)*test_set_size): 
    temp.append(int(random.random()*2**(input_bitwidth-1)))

test_data = []
test_data.append(temp)

tf_real = []
tf_imag = []
for i in range(no_inputs):
    tf_real.append(tuple([int(random.random()*2**(twiddle_bits-1)) for j in range(no_inputs)]))
    tf_imag.append(tuple([int(random.random()*2**(twiddle_bits-1)) for j in range(no_inputs)]))
    
tf_real = tuple(tf_real)
tf_imag = tuple(tf_imag)

reset = Signal(bool(False))
input_arc = Arc.Arc(reset,no_inputs,input_bitwidth,actor_scale,input_bitwidth,complex_valued,size_factor)
output_arc = Arc.Arc(reset,actor_scale,output_bitwidth,no_outputs,output_bitwidth,complex_valued,size_factor)

clk = Signal(bool(False))
dft = DFT.DFT(clk,input_arc,output_arc,tf_real,tf_imag,twiddle_bits,actor_scale)

#Simulation
signal_trace = traceSignals(test_bench_dft,dft,input_arc,output_arc,no_inputs,input_bitwidth,no_outputs,output_bitwidth,complex_valued,test_data,clk)
#simulation = Simulation(signal_trace)
#simulation.run(1000)

#Conversion

verilog_inst = toVerilog(dft_conversion_testbench,clk,reset,dft,input_arc,output_arc)
    def data_correct_check():
        print "Data Correct Signal Detected!"

    system_test_bench_inst = system_test_bench(clk, enable, reset,
                                               data_correct, arc, test_data)

    return instances()


no_inputs = 128
input_bitwidth = 8
no_outputs = 128
output_bitwidth = 8

system_test_bench_sim_inst = system_test_bench_sim(no_inputs, input_bitwidth,
                                                   no_outputs, output_bitwidth)
simulation = Simulation(system_test_bench_sim_inst)
simulation.run(100)

clk = Signal(bool(False))
enable = Signal(bool(False))
reset = Signal(bool(False))
data_correct = Signal(bool(False))

arc = Arc.Arc(reset, no_inputs, input_bitwidth, no_outputs, output_bitwidth,
              False, 1)

test_data = tuple([int(random.random() * 255) - 128 for i in range(no_inputs)])

verilog_inst = toVerilog(system_test_bench, clk, enable, reset, data_correct,
                         arc, test_data)
Esempio n. 8
0
import Arc as arc
import Node as node
import random
import VehicleDiscreteFlow as vehicle
import Event as event
import basicFunction as basic
import Arr_Time as arriveTime
from statistics import mean
import sensitivyParameter as parameter
import numpy as np

# initialization of the network
arc4_left = arc.arc("13thTo14th", 0.115)
node3_left = node.nodeIntersection("int13", arc4_left)
node3_left.stopSign = True
arc3_left = arc.arc("12thTo13th", 0.125, node3_left)
node2_left = node.nodeIntersection("int12", arc3_left)
arc2_left = arc.arc("11thTo12th", 0.14, node2_left)
node1_left = node.nodeIntersection("int11", arc2_left)
arc1_left = arc.arc("10thTo11th", 0.165, node1_left)
entranceNode_left = node.nodeIntersection("int10", arc1_left)

arc4_right = arc.arc("13thTo14th", 0.115)
node3_right = node.nodeIntersection("int13", arc4_right)
node3_right.stopSign = True
arc3_right = arc.arc("12thTo13th", 0.125, node3_right)
node2_right = node.nodeIntersection("int12", arc3_right)
arc2_right = arc.arc("11thTo12th", 0.14, node2_right)
node1_right = node.nodeIntersection("int11", arc2_right)
arc1_right = arc.arc("10thTo11th", 0.165, node1_right)
entranceNode_right = node.nodeIntersection("int10", arc1_right)
Esempio n. 9
0
            fig.clf()
            plt.close()

    return


if len(sys.argv) != 4:
    print '输入参数数目不对'
    exit()

map_file = open(sys.argv[1])
map_lines = map_file.readlines()
map_lines.pop(0)  # 删除第一行,为说明,非数据
# arc_objects存储着所有边的Arc对象实例,改成Arc不用Edgh命名是因为,Arc是有向边,Edgh是无向边
# 注意此处arc_objects列表中元素Arc的id比对应index大1,因为Arc的id从1开始,list的index从0开始
arc_objects = [Arc(argv.strip().split(',')) for argv in map_lines]

car_file = open(sys.argv[2])
car_lines_str = car_file.readlines()
# car_record_objects存储着汽车的每一条gps定位数据
car_record_objects = [CarRecord(line_str.strip().split(',')) for line_str in car_lines_str]
# car_id_count存储着从1到100每一辆车的gps定位数量
car_id = [car_record.car_id for car_record in car_record_objects]
car_num = max(car_id)
car_id_count = [car_id.count(i + 1) for i in range(car_num)]  # 100辆车

# 生成图的邻接表数据结构
map_graph = {}
for arc in arc_objects:
    if map_graph.has_key(arc.from_node):
        map_graph[arc_objects[arc.id - 1].from_node].append(arc)
Esempio n. 10
0
#Simulation Parameters
test_set_size = 16
#test_data = [range(no_inputs*no_outputs*test_set_size)]

temp = []
for i in range(test_set_size):
    temp.append([])
    for td in range(max(no_outputs, no_inputs)):
        temp[-1].append(int(random.random() * 2**(input_bitwidth - 1)))

test_data = temp

reset = Signal(bool(False))
input_arc = [
    Arc.Arc(reset, no_inputs, input_bitwidth, actor_scale, input_bitwidth,
            complex_valued, size_factor) for i in range(test_set_size)
]
output_arc = Arc.Arc(reset, actor_scale, output_bitwidth, no_outputs,
                     output_bitwidth, complex_valued, size_factor)

clk = Signal(bool(False))
mux = Pipeline_Mux.Pipeline_Mux(clk, input_arc, output_arc, actor_scale)

#Simulation
signal_trace = traceSignals(test_bench_mux, mux, input_arc, output_arc,
                            no_inputs, input_bitwidth, no_outputs,
                            output_bitwidth, complex_valued, test_data, clk)
#simulation = Simulation(signal_trace)
#simulation.run(100)

#Conversion