コード例 #1
0
ファイル: Random.py プロジェクト: aesteras/sim-port
 def initialization(self):
     random.seed(0)
     # se hace getNumTrucks para las tres
     self.numTrucksEntrega = self.getNumTrucks(Constants.ENTREGA)
     self.numTrucksRecogida = self.getNumTrucks(Constants.RECOGIDA)
     self.numTrucksDual = self.getNumTrucks(Constants.DUAL)
     self.numTrucks = self.getNumTrucks(None)
     p = Parameters()
     self.LAMBDA_Entrega = p.getTotalTime(
         Constants.ENTREGA) / self.numTrucksEntrega
     self.LAMBDA_Recogida = p.getTotalTime(
         Constants.RECOGIDA) / self.numTrucksRecogida
     self.LAMBDA_Dual = p.getTotalTime(Constants.DUAL) / self.numTrucksDual
     self.LAMBDA = p.getTotalTime(None) / self.numTrucks
コード例 #2
0
class TestParameters(TestCase):
    def setUp(self):
        self.parametersObj = Parameters()
        self.parametersObj.WITH_SHIFTS = True
        rand = Random()
        rand.initialization()

    def tearDown(self):
        self.parametersObj = None

    def test_getTotalTime(self):
        shift_duration = [5, 9, 2, 1]
        shift_type = [
            Constants.ENTREGA, Constants.ENTREGA, Constants.RECOGIDA,
            Constants.DUAL
        ]
        shift_factor = 3600  # hours
        self.parametersObj.setParameters(shift_duration, shift_type,
                                         shift_factor)

        self.assertEqual(self.parametersObj.getTotalTime(Constants.ENTREGA),
                         14, "The delivery time should be 5 + 9")
        self.assertEqual(self.parametersObj.getTotalTime(Constants.RECOGIDA),
                         2, "The collection time should be 2")
        self.assertEqual(self.parametersObj.getTotalTime(Constants.DUAL), 1,
                         "The dual time should be 1")

    def test_getCurrentShift_Not_Edges(self):
        shift_duration = [5, 9, 2, 1]
        # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
        # E E E E E E E E E E E  E  E  E  R  R  D
        shift_type = [
            Constants.ENTREGA, Constants.ENTREGA, Constants.RECOGIDA,
            Constants.DUAL
        ]
        shift_factor = 3600  # hours
        self.parametersObj.setParameters(shift_duration, shift_type,
                                         shift_factor)

        self.assertEqual(
            self.parametersObj.getCurrentShift(
                Constants.SIMULATION_INITIAL_TIME + 2 * 3600),
            Constants.ENTREGA, "The shift should be ENTREGA")
        self.assertEqual(
            self.parametersObj.getCurrentShift(
                Constants.SIMULATION_INITIAL_TIME + 7 * 3600),
            Constants.ENTREGA, "The shift should be ENTREGA")
        self.assertEqual(
            self.parametersObj.getCurrentShift(
                Constants.SIMULATION_INITIAL_TIME + 15 * 3600),
            Constants.RECOGIDA, "The shift should be RECOGIDA")
        self.assertEqual(
            self.parametersObj.getCurrentShift(
                Constants.SIMULATION_INITIAL_TIME + 17 * 3600), Constants.DUAL,
            "The shift should be DUAL")

    def test_getCurrentShift_Edges(self):
        shift_duration = [5, 9, 2, 1]
        # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
        # E E E E E E E E E E E  E  E  E  R  R  D
        shift_type = [
            Constants.ENTREGA, Constants.ENTREGA, Constants.RECOGIDA,
            Constants.DUAL
        ]
        shift_factor = 3600  # hours
        self.parametersObj.setParameters(shift_duration, shift_type,
                                         shift_factor)

        self.assertEqual(
            self.parametersObj.getCurrentShift(
                Constants.SIMULATION_INITIAL_TIME + 0 * 3600),
            Constants.ENTREGA, "The shift should be ENTREGA")
        self.assertEqual(
            self.parametersObj.getCurrentShift(
                Constants.SIMULATION_INITIAL_TIME + 13 * 3600),
            Constants.ENTREGA, "The shift should be ENTREGA")
        self.assertEqual(
            self.parametersObj.getCurrentShift(
                Constants.SIMULATION_INITIAL_TIME + 14 * 3600),
            Constants.RECOGIDA, "The shift should be RECOGIDA")
        self.assertEqual(
            self.parametersObj.getCurrentShift(
                Constants.SIMULATION_INITIAL_TIME + 15 * 3600),
            Constants.RECOGIDA, "The shift should be RECOGIDA")
        self.assertEqual(
            self.parametersObj.getCurrentShift(
                Constants.SIMULATION_INITIAL_TIME + 16 * 3600), Constants.DUAL,
            "The shift should be DUAL")