示例#1
0
 def __init__(self, tspName, numOfVehicles, depotIndex):
     """
     Creates an instance of a VRP
     :param tspName: name of the underlying TSP
     :param numOfVehicles: number of vehicles used
     :param depotIndex: the index of the TSP city that will be used as the depot location
     """
     self.tsp = tsp.TravelingSalesmanProblem(tspName)
     self.numOfVehicles = numOfVehicles
     self.depotIndex = depotIndex
示例#2
0
import array

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

import tsp
import elitism

# set the random seed for repeatable results
RANDOM_SEED = 42
random.seed(RANDOM_SEED)

# create the desired traveling salesman problem instace:
TSP_NAME = "bayg29"  # name of problem
tsp = tsp.TravelingSalesmanProblem(TSP_NAME)

# Genetic Algorithm constants:
POPULATION_SIZE = 300
MAX_GENERATIONS = 200
HALL_OF_FAME_SIZE = 30
P_CROSSOVER = 0.9  # probability for crossover
P_MUTATION = 0.1   # probability for mutating an individual

toolbox = base.Toolbox()

# define a single objective, minimizing fitness strategy:
creator.create("FitnessMin", base.Fitness, weights=(-1.0,))

# create the Individual class based on list of integers:
creator.create("Individual", array.array, typecode='i', fitness=creator.FitnessMin)