Пример #1
0
 def test_delete(self):
     repo=repository()
     repo.add_bicicleta(1,'tip',5)
     repo.add_bicicleta(5,'tip',5)
     repo.add_bicicleta(3,'tip',5)
     repo.delete(5)
     lungime=len(repo.get_all())
     self.assertEquals(lungime,2)
Пример #2
0
def main():
    m = Map(mapLengh, mapLengh)
    m.randomMap()
    # init = setUpParamsManually(m)
    init = setUpParamsRandom(m)
    if init is None:
        print(
            "Incorrect data introduced. Sensors/Drone may overlap forbidden positions."
        )
        return

    drone = init[0]
    droneEnergy = init[1]
    sensors = init[2]
    repo = repository(m, drone, droneEnergy, sensors)
    c = controller(repo)
    c.initializeDistanceMatrix()

    dm = c.getDistanceMatrix()

    antColonyDistanceMatrix = np.zeros((SENSORS + 1, SENSORS + 1))

    for i in range(SENSORS):
        antColonyDistanceMatrix[i][SENSORS] = drone.distances[i]
        antColonyDistanceMatrix[SENSORS][i] = drone.distances[i]

    for i in range(SENSORS):
        for j in range(SENSORS):
            antColonyDistanceMatrix[i][j] = dm[i][j]

    for i in range(len(antColonyDistanceMatrix)):
        for j in range(len(antColonyDistanceMatrix)):
            if antColonyDistanceMatrix[i][j] == 0.0 and i != j:
                print("One or more sensors is/are unreachable")
                return
    """
    for i in range(SENSORS + 1):
        for j in range(SENSORS + 1):
            print(antColonyDistanceMatrix[i][j], end=" ")
        print()
    """

    aco = AntColonyOptimization(antColonyDistanceMatrix)
    pathLength, path = aco.run()

    finalPath = c.makePath(pathLength, path)
    path, result = c.adjustBatteryToPath(finalPath)
    for e in result:
        print("Sensor (" + str(e[0]) + ", " + str(e[1]) + ") : " + str(e[2]) +
              " seen squares using " + str(e[3]) + " battery")
    movingDrone(m, path, sensors, drone, 0.1)
Пример #3
0
 def test_add(self):
     repo=repository()
     repo.add_bicicleta(1,'tip',5)
     lungime=len(repo.get_all())
     self.assertEquals(lungime,1)
Пример #4
0
 def __init__(self):
     self.__currentIteration = 0
     self.__repository = repository()
Пример #5
0
    plt.ylabel('Average fitness per generation')
    plt.xlabel('Generation number')
    plt.show()
    return results[0]


if __name__ == '__main__':
    args = []
    args.append(populationSize)
    args.append(inidividualSize)
    args.append(initialCoordinates)
    args.append(map)
    args.append(crossOverProb)
    args.append(mutateProb)

    repository = repository()
    controller = controller(args, repository)
    # f = open("Stats/test.txt", "a")
    # f.write("-------------------------------------------------------\n")
    # f.write("|  Seed  |  Average Deviation  |  Standard Deviation  |\n")
    # f.close()
    for i in range(1):
        repository.createPopulation(args)
        path = oneRun()
        seed = seeds[i]
        random.seed(seed)
        fitAvg = repository.getFitnessAvg()
        data = np.array(fitAvg)

        # averageDev = np.average(data)
        # standardDev = data.std()