def test_fitness_calculation(self): # Make sure out fitness calculation returns # what we expect. locations = [] locations.append(Location("A", 20, 20)) locations.append(Location("B", 60, 20)) locations.append(Location("C", 60, 30)) salesman = Salesman(locations) fitness = salesman.calculate_fitness() self.assertEqual(fitness, 50)
def InitSalesmen(self, salesmen): self.salesmen = [] index = 0 for salesman in salesmen: self.salesmen.append( Salesman(salesman["position"], self.colors[index])) index = index + 1 self.map_panel.salesmen = self.salesmen
def main(argv): number_of_cities = stdin.readline() salesman = Salesman(int(number_of_cities)) salesman.getCities() salesman.mountMap() tour, distance = salesman.travel() stdout.write("%.2f\n" % distance) for city in tour: stdout.write("%d " % city) stdout.write("\n") return 0
def main(): parser = ArgumentParser(description="Check all links") parser.add_argument("action", type=str, choices=["visit", "explore"], help=("What action Salesman should take")) parser.add_argument("url", type=str, help="Absolute URL") args = parser.parse_args() willy_lowman = Salesman() print "Traveling your website. This could take O(n^2*2^n) time" if args.action == "visit": if os.path.isfile(args.url): urls = open(args.url).readlines() willy_lowman.verify(*urls) else: willy_lowman.verify(args.url) else: willy_lowman.explore(args.url) print "Tested {} urls".format(len(willy_lowman.visited_urls))
status = "fail" if val_1 == 1 and val_2 == 0: status = "ok" print message print "1: {} -- 2: {} -- status: {}".format(val_1, val_2, status) print "\n\n" #################################### ########## salesman.py ############# #################################### sales_man = Salesman() print "salesman testing" print "error : " print sales_man.InitByEmail("*****@*****.**") sales_man.name = "test" sales_man.password = "******" sales_man.email = "*****@*****.**" sales_man.identifier = "1" ## save and load print "save: {}".format(sales_man.Save()) print "cnt : {}".format(db.salesman.find().count()) print "load: {}".format(sales_man.InitByEmail("*****@*****.**"))
def create_salesman(nodenum): salesman = Salesman(np.arange(1, nodenum)) np.random.shuffle(salesman.route) return salesman
type=str, help='Set the output filename(json).') args = parser.parse_args() # Check argument by standard output print(args) # Set arguments to variables problem = args.problem filename = args.filename crossover_prob = args.crossover_prob mutation_prob = args.mutation_prob popSize = args.population_size generation = args.generation # Traveling Salesman Problem Dataset dataset = Salesman(filename) dataset.read() gene_size = len(dataset.location) # Generate each GA instance tspga = GeneticAlgorithm(gene_size, popSize, crossover_prob, mutation_prob) best_fitness = [] mean_fitness = [] print('Ranking', end=' ') tspga.initialization() bf, mf = tspga.calculateFitness(dataset) best_fitness.append(bf) mean_fitness.append(mf)
from magazine import Magazine from storage import Storage from item import Item from salesman import Salesman # --------------------------- Sandbox ---------------------------- seller_r2d2 = Salesman("r2d2") seller_2 = Salesman("Petya") seller_r2d2.show_sales() cabbage = Item("cabbage", 10, 15) carrot = Item("carrot", 4, 8) rabbit_breast = Item("rabbit_breast", 80, 110) storage = Storage() storage.add_item(cabbage, 50) storage.add_item(carrot, 130) storage.add_item(rabbit_breast, 20) storage.item_balance(item=carrot) storage.withdraw_item(carrot, 20) storage.item_balance() storage.item_balance() magazine = Magazine() magazine.write_off(carrot, 20, storage) magazine.show_income()