Exemplo n.º 1
0
class CostEngine:
    def __init__(self, test_flights_info, zoneOptions, npts_per_leg, flightParamsTemplate, submission_file):
        self.test_flights_info  = test_flights_info
        self.zoneOptions        = zoneOptions
        self.npts_per_leg       = npts_per_leg
        self.submission_file    = submission_file
        self.flightParamsTemplate = flightParamsTemplate
        print "Starting simulator..."
        self.simulator = Simulator()
        print "Simulator started."

    def cost(self, vecFlightParams):
        flightParams = vectorToFlightParams(vecFlightParams, self.flightParamsTemplate)
        flightModel  = FlightModel(**flightParams)  # waypoints.FlightModel
        write_submission( self.test_flights_info, flightModel, 
                          self.zoneOptions, self.npts_per_leg, self.submission_file )
        submission_file_basename = os.path.basename(self.submission_file)
        sim_cost = self.simulator.cost(submission_file_basename)
        print time.asctime(), "currentCost:", sim_cost, "zoneOptions:", self.zoneOptions
        return sim_cost

    def stop(self):
        self.simulator.stop()
class CostEngine:
    def __init__(self, flightParamsTemplate, submissionFile, testFlightsFile):
        self.submissionFile = submissionFile
        self.flightParamsTemplate = flightParamsTemplate
        self.testFlightsFile = testFlightsFile
        print "Starting simulator using:", testFlightsFile
        self.simulator = Simulator()
        print "Simulator started."

    def cost(self, flightParamsVector):
        # write submission waypoints (to submission_file)
        flightParams = vectorToFlightParams(flightParamsVector,
                                            self.flightParamsTemplate)
        basicAgent.make_basicAgent_submission(self.submissionFile,
                                              self.testFlightsFile,
                                              **flightParams)
        # calcuate cost using the simulator
        submission_file_basename = os.path.basename(self.submissionFile)
        sim_cost = self.simulator.cost(submission_file_basename)
        # print time.asctime(), "currentCost:", sim_cost, "parameters:", flightParams
        return sim_cost

    def stop(self):
        self.simulator.stop()