def testDefaults(self):
   cost_accumulator = cost_accumulator_.FactorCostAccumulatorGenerator().Generate()
   self.assertEqual(0., cost_accumulator.Cost())
   cost_accumulator.AddMoveBetween(
       city_visit.MoveDescription(
           self.san_francisco_coordinates,
           self.points['Ferry Building'].coordinates_starts,
           1.25, city_visit.MoveType.walking))
   self.assertEqual(1.25, cost_accumulator.Cost())
   cost_accumulator.AddPointVisit(self.points['Ferry Building'])
   self.assertEqual(2.25, cost_accumulator.Cost())
   cost_accumulator.AddLunch(1.0)
   self.assertEqual(3.25, cost_accumulator.Cost())
   cost_accumulator.AddMoveBetween(
       city_visit.MoveDescription(
           self.points['Ferry Building'].coordinates_ends,
           self.points['Pier 39'].coordinates_starts,
           0.05, city_visit.MoveType.driving))
   self.assertEqual(3.30, cost_accumulator.Cost())
   cost_accumulator.AddPointVisit(self.points['Pier 39'])
   self.assertEqual(6.30, cost_accumulator.Cost())
   cost_accumulator.AddMoveBetween(
       city_visit.MoveDescription(
           self.points['Pier 39'].coordinates_ends,
           self.san_francisco_coordinates,
           0.50, city_visit.MoveType.ptt))
   self.assertEqual(6.80, cost_accumulator.Cost())
   cost_accumulator.AddPointLeft(self.points['Golden Gate Bridge'])
   self.assertEqual(7.30, cost_accumulator.Cost())
   cost_accumulator.AddUnusedTime(timedelta(hours=0.005))
   self.assertAlmostEqual(7.60, cost_accumulator.Cost())
   cost_accumulator.AddUnusedTime(timedelta(seconds=30))
   self.assertAlmostEqual(8.10, cost_accumulator.Cost())
示例#2
0
 def setUp(self):
     self.no_point_visit_factor = 0.
     self.no_point_visit_const = 1000.
     self.unused_time_factor = 0.01
     cost_accumulator_generator = cost_accumulator.FactorCostAccumulatorGenerator(
         no_point_visit_factor=self.no_point_visit_factor,
         no_point_visit_const=self.no_point_visit_const,
         unused_time_factor=self.unused_time_factor)
     self.city_visit_points_left_generator = (
         city_visit_points_left_.CityVisitPointsLeftGenerator(
             cost_accumulator_generator=cost_accumulator_generator))
     super(CityVisitPointsLeftTest, self).setUp()
示例#3
0
 def setUp(self):
   self.no_point_visit_factor = 0.
   self.no_point_visit_const = 1000.
   self.unused_time_factor = 0.01
   self.points = test_util.MockPoints()
   move_calculator = test_util.MockMoveCalculator()
   point_fit = point_fit_.SimplePointFit()
   cost_accumulator_generator=cost_accumulator.FactorCostAccumulatorGenerator(
       no_point_visit_factor=self.no_point_visit_factor,
       no_point_visit_const=self.no_point_visit_const,
       unused_time_factor=self.unused_time_factor)
   self.day_visit_cost_calculator_generator = day_visit_cost_calculator_.DayVisitCostCalculatorGenerator(
       move_calculator=move_calculator,
       point_fit=point_fit,
       cost_accumulator_generator=cost_accumulator_generator)
   super(DayVisitCostCalculatorTest, self).setUp()
示例#4
0
 def setUp(self):
     no_point_visit_factor = 0.
     no_point_visit_const = 1000.
     unused_time_factor = 0.01
     day_visit_heap_size = 1000
     self.points = test_util.MockPoints()
     move_calculator = test_util.MockMoveCalculator()
     point_fit = point_fit_.SimplePointFit()
     cost_accumulator_generator = cost_accumulator.FactorCostAccumulatorGenerator(
         no_point_visit_factor=no_point_visit_factor,
         no_point_visit_const=no_point_visit_const,
         unused_time_factor=unused_time_factor)
     day_visit_cost_calculator_generator = day_visit_cost_calculator.DayVisitCostCalculatorGenerator(
         move_calculator=move_calculator,
         point_fit=point_fit,
         cost_accumulator_generator=cost_accumulator_generator)
     self.day_visit_router = day_visit_router.DayVisitRouter(
         calculator_generator=day_visit_cost_calculator_generator,
         day_visit_heap_size=day_visit_heap_size)
     super(DayVisitRouterTest, self).setUp()
 def testGeneral(self):
   cost_accumulator = cost_accumulator_.FactorCostAccumulatorGenerator(
       point_visit_factor=0.5,
       move_walking_factor=1.,
       move_driving_factor=2.,
       move_ptt_factor=3.,
       lunch_factor=0.25,
       no_point_visit_factor=10.,
       no_point_visit_const=100.,
       unused_time_factor=2.).Generate()
   self.assertEqual(0., cost_accumulator.Cost())
   cost_accumulator.AddMoveBetween(
       city_visit.MoveDescription(
           self.san_francisco_coordinates,
           self.points['Ferry Building'].coordinates_starts,
           1.25, city_visit.MoveType.walking))
   self.assertEqual(1.25, cost_accumulator.Cost())
   cost_accumulator.AddPointVisit(self.points['Ferry Building'])
   self.assertEqual(1.75, cost_accumulator.Cost())
   cost_accumulator.AddLunch(1.0)
   self.assertEqual(2.00, cost_accumulator.Cost())
   cost_accumulator.AddMoveBetween(
       city_visit.MoveDescription(
           self.points['Ferry Building'].coordinates_ends,
           self.points['Pier 39'].coordinates_starts,
           0.05, city_visit.MoveType.driving))
   self.assertEqual(2.10, cost_accumulator.Cost())
   cost_accumulator.AddPointVisit(self.points['Pier 39'])
   self.assertEqual(3.60, cost_accumulator.Cost())
   cost_accumulator.AddMoveBetween(
       city_visit.MoveDescription(
           self.points['Pier 39'].coordinates_ends,
           self.san_francisco_coordinates,
           0.50, city_visit.MoveType.ptt))
   self.assertEqual(5.10, cost_accumulator.Cost())
   cost_accumulator.AddPointLeft(self.points['Golden Gate Bridge'])
   self.assertEqual(110.10, cost_accumulator.Cost())
   cost_accumulator.AddUnusedTime(timedelta(hours=0.005))
   self.assertAlmostEqual(110.70, cost_accumulator.Cost())
   cost_accumulator.AddUnusedTime(timedelta(seconds=30))
   self.assertAlmostEqual(111.70, cost_accumulator.Cost())
示例#6
0
 def setUp(self):
     no_point_visit_factor = 0.
     no_point_visit_const = 1000.
     unused_time_factor = 0.01
     day_visit_heap_size = 1000
     shard_num_days = 2
     max_depth = 1
     city_visit_heap_size = 10
     max_non_pushed_points = 3
     self.points = test_util.MockPoints()
     move_calculator = test_util.MockMoveCalculator()
     point_fit = point_fit_.SimplePointFit()
     cost_accumulator_generator = cost_accumulator.FactorCostAccumulatorGenerator(
         no_point_visit_factor=no_point_visit_factor,
         no_point_visit_const=no_point_visit_const,
         unused_time_factor=unused_time_factor)
     day_visit_cost_calculator_generator = day_visit_cost_calculator.DayVisitCostCalculatorGenerator(
         move_calculator=move_calculator,
         point_fit=point_fit,
         cost_accumulator_generator=cost_accumulator_generator)
     day_visit_router = day_visit_router_.DayVisitRouter(
         calculator_generator=day_visit_cost_calculator_generator,
         day_visit_heap_size=day_visit_heap_size)
     city_visit_points_left_generator = city_visit_points_left.CityVisitPointsLeftGenerator(
         cost_accumulator_generator=cost_accumulator_generator)
     points_queue_generator = points_queue.OneByOnePointsQueueGenerator()
     self.city_visit_router = city_visit_router.CityVisitRouter(
         day_visit_router=day_visit_router,
         city_visit_points_left_generator=city_visit_points_left_generator,
         points_queue_generator=points_queue_generator,
         shard_num_days=shard_num_days,
         max_depth=max_depth,
         city_visit_heap_size=city_visit_heap_size,
         max_non_pushed_points=max_non_pushed_points,
         num_processes=None)
     self.city_visit_accumulator_generator = city_visit_accumulator.CityVisitAccumulatorGenerator(
     )
     super(CityVisitRouterTest, self).setUp()
示例#7
0
def GetCostAccumulatorGenerator(config):
  cag_section = 'cost_accumulator_generator'
  
  point_visit_factor = config.getfloat(cag_section, 'point_visit_factor')
  move_walking_factor = config.getfloat(cag_section, 'move_walking_factor')
  move_driving_factor = config.getfloat(cag_section, 'move_driving_factor')
  move_ptt_factor = config.getfloat(cag_section, 'move_ptt_factor')
  lunch_factor = config.getfloat(cag_section, 'lunch_factor')
  no_point_visit_factor = config.getfloat(cag_section, 'no_point_visit_factor')
  no_point_visit_const = config.getfloat(cag_section, 'no_point_visit_const')
  unused_time_factor = config.getfloat(cag_section, 'unused_time_factor')
  
  cost_accumulator_generator = cost_accumulator.FactorCostAccumulatorGenerator(
      point_visit_factor=point_visit_factor,
      move_walking_factor=move_walking_factor,
      move_driving_factor=move_driving_factor,
      move_ptt_factor=move_ptt_factor,
      lunch_factor=lunch_factor,
      no_point_visit_factor=no_point_visit_factor,
      no_point_visit_const=no_point_visit_const,
      unused_time_factor=unused_time_factor)
  
  return cost_accumulator_generator