def GetCount(self, graph, num):
     nodeCount = graph.GetNodes()
     number = str(num)
     if number.find("%"):
         number = number.strip("%")
         if Utility.CheckParameter("(FLOAT2)", number):
             return int(float(number) * nodeCount / 100.0)
     else:
         if Utility.CheckParameter("(FLOAT2)", number):
             if number <= nodeCount:
                 return number
             else:
                 return nodeCount
Exemplo n.º 2
0
    def ClickSetting(self):
        setStep = 0
        if self.radioButtonSteps.isChecked():
            if self.lineEditStep.text() == "":
                Utility.SystemWarning(
                    "Please input the number of simulation steps!")
                return
            if self.lineEditEmergencyIndexValue.text() == "":
                Utility.SystemWarning(
                    "Please input the default value of emergency index!")
                return
            if not Utility.CheckParameter(
                    "(FLOAT)", self.lineEditEmergencyIndexValue.text()):
                Utility.SystemWarning(
                    "Please set urgency index (0~1) for each step!")
                return
            setStep = int(self.lineEditStep.text())
        elif self.radioButtonPercentage.isChecked():
            setStep = 1

        while self.tableWidgetEmergencyIndex.rowCount() < setStep:
            print self.tableWidgetEmergencyIndex.rowCount()
            print self.lineEditStep.text()
            i = self.tableWidgetEmergencyIndex.rowCount()
            self.tableWidgetEmergencyIndex.insertRow(i)
            item = QtGui.QTableWidgetItem()
            item.setText(self.lineEditEmergencyIndexValue.text())
            self.tableWidgetEmergencyIndex.setItem(i, 0, item)
        while self.tableWidgetEmergencyIndex.rowCount() > setStep:
            self.tableWidgetEmergencyIndex.removeRow(setStep)

        for i in range(setStep):
            item = QtGui.QTableWidgetItem()
            item.setText(self.lineEditEmergencyIndexValue.text())
            self.tableWidgetEmergencyIndex.setItem(i, 0, item)
Exemplo n.º 3
0
    def ClickSimulation(self):
        step = 0
        coverage = 0
        if self.radioButtonSteps.isChecked():
            if not Utility.CheckParameter("(INT)", self.lineEditStep.text()):
                Utility.SystemWarning(
                    "Please make sure you input a positive integer in the textbox for step "
                )
                return
            step = int(self.lineEditStep.text())
        elif self.radioButtonPercentage.isChecked():
            if not Utility.CheckParameter("(FLOAT2)",
                                          self.lineEditPercentage.text()):
                Utility.SystemWarning(
                    "Please make sure you input a positive float in the textbox for coverage "
                )
                return
            coverage = int(self.lineEditPercentage.text())

        # increment = 0.025

        # simulationSpeeds = []
        # speeds = [round(i*increment,3) for i in range(int(1/increment*0.35))]
        # simulationSpeeds = list(product(speeds, repeat=step))

        # simulationSpeeds = []
        # for i in range(100):
        # speeds = []
        # for j in range(4):
        # speeds.append((i+1)/100.0)
        # simulationSpeeds.append(speeds)

        tem_speeds = [0.1, 0.2, 0.2, 0.1]
        simulationSpeeds = []
        for j in range(1, 50):
            speeds = []
            for i in range(4):
                speed = tem_speeds[i] * j / 10
                speeds.append(round(speed, 3))
            simulationSpeeds.append(speeds)

        # for j in range(10):
        # speeds = []
        # for i in range(10):
        # if i > 4:
        # speeds.append(((10/(j+1.0))-(i+1.0)/(j+1))/10+0.2)
        # else:
        # speeds.append(((i+1.0)/(j+1))/10+0.2)
        # simulationSpeeds.append(speeds)

        for speed in simulationSpeeds:
            self.lastLine = None

            # step = 0
            # coverage = 0
            # if self.radioButtonSteps.isChecked():
            # if not Utility.CheckParameter("(INT)", self.lineEditStep.text()):
            # Utility.SystemWarning("Please make sure you input a positive integer in the textbox for step ")
            # return
            # step = int(self.lineEditStep.text())
            # elif self.radioButtonPercentage.isChecked():
            # if not Utility.CheckParameter("(FLOAT2)", self.lineEditPercentage.text()):
            # Utility.SystemWarning("Please make sure you input a positive float in the textbox for coverage ")
            # return
            # coverage = int(self.lineEditPercentage.text())

            emergencyIndexType = "G"
            decayedCircle = 0.0
            decayedRatio = 0.0
            if self.radioButtonRegional.isChecked():
                emergencyIndexType = "R"
                if not Utility.CheckParameter(
                        "(FLOAT2)", self.lineEditDecayedRadius.text()):
                    Utility.SystemWarning(
                        "Please make sure you input a positive float in the textbox for decayed circle "
                    )
                    return
                decayedCircle = float(self.lineEditDecayedRadius.text())

                if not Utility.CheckParameter(
                        "(FLOAT2)", self.lineEditDecayedRatio.text()):
                    Utility.SystemWarning(
                        "Please make sure you input a positive float (0~100) in the textbox for decayed ratio "
                    )
                    return
                else:
                    ratio = float(self.lineEditDecayedRatio.text())
                    if ratio < 0 or ratio > 100:
                        Utility.SystemWarning(
                            "Please make sure you input a positive float (0~100) in the textbox for decayed ratio "
                        )
                        return
                decayedRatio = float(self.lineEditDecayedRatio.text())

            # simulation purpose only, hard-coded.

            emergencyIndexType = "R"
            decayedCircle_list = [50, 100, 150, 200, 250, 300, 350, 400]
            for dc in decayedCircle_list:
                decayedRatio_list = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95]
                for dr in decayedRatio_list:
                    decayedCircle = dc
                    decayedRatio = dr

                    seedNodes = set()
                    if self.textEditSeedNodes.toPlainText() == "":
                        Utility.SystemWarning(
                            "Please make sure you input the ID of seed nodes!")
                        return
                    seedNodesList = self.textEditSeedNodes.toPlainText().split(
                        ";")
                    for i in range(len(seedNodesList)):
                        try:
                            seedNodes.add(int(seedNodesList[i]))
                        except:
                            Utility.SystemWarning(
                                "Please make sure you input the ID of seed nodes that are separated by semicolon!"
                            )
                            return
                    if len(self.weightMatrix) == 0:
                        Utility.SystemWarning(
                            "Please make sure you load weight matrix file!")
                        return

                    self.diffusionThread = CityDiffusion2.CityDiffusion(
                        self.graph, seedNodes, self.weightMatrix, speed, step,
                        coverage, self.nodesLatLonPostion, emergencyIndexType,
                        [decayedCircle, decayedRatio])

                    #self.connect(self.diffusionThread, QtCore.SIGNAL("ActiveNodeCityDiffusion(int, int, int)"),
                    #             self.ActiveNodeCityDiffusion)
                    #self.connect(self.diffusionThread, QtCore.SIGNAL("FinishedDiffusion(QString)"), self.FinishedDiffusion)

                    self.pushButtonSimulation.setEnabled(False)
                    # self.RestoreDiffusionNodes()
                    self.BeginDiffusion()
                    time.sleep(0.5)
                    self.diffusionThread.start()
                    i += 1
            """
            seedNodes = set()
            if self.textEditSeedNodes.toPlainText() == "":
                Utility.SystemWarning("Please make sure you input the ID of seed nodes!")
                return
            seedNodesList = self.textEditSeedNodes.toPlainText().split(";")
            for i in range(len(seedNodesList)):
                try:
                    seedNodes.add(int(seedNodesList[i]))
                except:
                    Utility.SystemWarning("Please make sure you input the ID of seed nodes that are separated by semicolon!")
                    return
            if len(self.weightMatrix) == 0:
                Utility.SystemWarning("Please make sure you load weight matrix file!")
                return


            self.diffusionThread = CityDiffusion2.CityDiffusion(self.graph, seedNodes, self.weightMatrix, speed, step, coverage, self.nodesLatLonPostion, emergencyIndexType, [decayedCircle, decayedRatio])

            # self.connect(self.diffusionThread, QtCore.SIGNAL("ActiveNodeCityDiffusion(int, int, int)"),
                         # self.ActiveNodeCityDiffusion)
            # self.connect(self.diffusionThread, QtCore.SIGNAL("FinishedDiffusion(QString)"), self.FinishedDiffusion)

            self.pushButtonDiffusion.setEnabled(False)
            # self.RestoreDiffusionNodes()
            self.BeginDiffusion()
            time.sleep(0.5)
            self.diffusionThread.start()
            """
        self.pushButtonSimulation.setEnabled(True)
Exemplo n.º 4
0
    def ClickDiffusion(self):
        self.lastLine = None

        step = 0
        coverage = 0
        if self.radioButtonSteps.isChecked():
            if not Utility.CheckParameter("(INT)", self.lineEditStep.text()):
                Utility.SystemWarning(
                    "Please make sure you input a positive integer in the textbox for step "
                )
                return
            step = int(self.lineEditStep.text())
        elif self.radioButtonPercentage.isChecked():
            if not Utility.CheckParameter("(FLOAT2)",
                                          self.lineEditPercentage.text()):
                Utility.SystemWarning(
                    "Please make sure you input a positive float in the textbox for coverage "
                )
                return
            coverage = int(self.lineEditPercentage.text())

        speed = []
        rowCount = self.tableWidgetEmergencyIndex.rowCount()

        if self.radioButtonSteps.isChecked():
            if rowCount != step:
                Utility.SystemWarning(
                    "Please set urgency index (0~1) for each step!")
                return
            else:
                for i in range(step):
                    if not Utility.CheckParameter(
                            "(FLOAT)",
                            self.tableWidgetEmergencyIndex.item(i, 0).text()):
                        Utility.SystemWarning(
                            "Please set urgency index (0~1) for each step!")
                        return
                    currentSpeed = float(
                        self.tableWidgetEmergencyIndex.item(i, 0).text())
                    speed.append(currentSpeed)
        elif self.radioButtonPercentage.isChecked():
            if rowCount != 1:
                Utility.SystemWarning("Please set urgency index (0~1)!")
                return
            else:
                for i in range(1):
                    if not Utility.CheckParameter(
                            "(FLOAT)",
                            self.tableWidgetEmergencyIndex.item(i, 0).text()):
                        Utility.SystemWarning(
                            "Please set urgency index (0~1) for each step!")
                        return
                    currentSpeed = float(
                        self.tableWidgetEmergencyIndex.item(i, 0).text())
                    speed.append(currentSpeed)

        emergencyIndexType = "G"
        decayedCircle = 0.0
        decayedRatio = 0.0
        if self.radioButtonRegional.isChecked():
            emergencyIndexType = "R"
            if not Utility.CheckParameter("(FLOAT2)",
                                          self.lineEditDecayedRadius.text()):
                Utility.SystemWarning(
                    "Please make sure you input a positive float in the textbox for decayed circle "
                )
                return
            decayedCircle = float(self.lineEditDecayedRadius.text())

            if not Utility.CheckParameter("(FLOAT2)",
                                          self.lineEditDecayedRatio.text()):
                Utility.SystemWarning(
                    "Please make sure you input a positive float (0~100) in the textbox for decayed ratio "
                )
                return
            else:
                ratio = float(self.lineEditDecayedRatio.text())
                if ratio < 0 or ratio > 100:
                    Utility.SystemWarning(
                        "Please make sure you input a positive float (0~100) in the textbox for decayed ratio "
                    )
                    return
            decayedRatio = float(self.lineEditDecayedRatio.text())

        seedNodes = set()
        if self.textEditSeedNodes.toPlainText() == "":
            Utility.SystemWarning(
                "Please make sure you input the ID of seed nodes!")
            return
        seedNodesList = self.textEditSeedNodes.toPlainText().split(";")
        for i in range(len(seedNodesList)):
            try:
                seedNodes.add(int(seedNodesList[i]))
            except:
                Utility.SystemWarning(
                    "Please make sure you input the ID of seed nodes that are separated by semicolon!"
                )
                return
        if len(self.weightMatrix) == 0:
            Utility.SystemWarning(
                "Please make sure you load weight matrix file!")
            return

        self.diffusionThread = CityDiffusion2.CityDiffusion(
            self.graph, seedNodes, self.weightMatrix, speed, step, coverage,
            self.nodesLatLonPostion, emergencyIndexType,
            [decayedCircle, decayedRatio])

        self.connect(self.diffusionThread,
                     QtCore.SIGNAL("ActiveNodeCityDiffusion(int, int, int)"),
                     self.ActiveNodeCityDiffusion)
        self.connect(self.diffusionThread,
                     QtCore.SIGNAL("FinishedDiffusion(QString)"),
                     self.FinishedDiffusion)

        self.pushButtonDiffusion.setEnabled(False)
        # self.RestoreDiffusionNodes()
        self.BeginDiffusion()
        time.sleep(0.5)
        self.diffusionThread.start()