Beispiel #1
0
class TestDSC(unittest.TestCase):
    """ Tests the solver Degree of Strong Controllability

    """
    logger = logging.getLogger('stn.test')

    def setUp(self):
        # Load the stn as a dictionary
        with open(STNU) as json_file:
            stnu_dict = json.load(json_file)

        # Convert the dict to a json string
        stnu_json = json.dumps(stnu_dict)

        self.stp = STP('dsc')
        self.stn = self.stp.get_stn(stn_json=stnu_json)

    def test_build_stn(self):
        self.logger.info("STNU: \n %s", self.stn)

        self.logger.info("Getting Schedule...")
        schedule = self.stp.solve(self.stn)

        self.logger.info("DSC: %s ", schedule.risk_metric)
        self.logger.info("schedule: %s ", schedule)

        completion_time = schedule.get_completion_time()
        makespan = schedule.get_makespan()

        self.logger.info("Completion time: %s ", completion_time)
        self.logger.info("Makespan: %s ", makespan)

        self.assertEqual(completion_time, 157)
        self.assertEqual(makespan, 98)

        expected_risk_metric = 0.0
        self.assertEqual(schedule.risk_metric, expected_risk_metric)

        constraints = schedule.get_constraints()

        for (i, j) in constraints:
            if i == 0 and j == 1:
                lower_bound = -schedule[j][i]['weight']
                upper_bound = schedule[i][j]['weight']
                self.assertEqual(lower_bound, 37)
                self.assertEqual(upper_bound, 37)
            if i == 0 and j == 2:
                lower_bound = -schedule[j][i]['weight']
                upper_bound = schedule[i][j]['weight']
                self.assertEqual(lower_bound, 41)
                self.assertEqual(upper_bound, 45)
            if i == 0 and j == 3:
                lower_bound = -schedule[j][i]['weight']
                upper_bound = schedule[i][j]['weight']
                self.assertEqual(lower_bound, 43)
                self.assertEqual(upper_bound, 51)
            if i == 0 and j == 4:
                lower_bound = -schedule[j][i]['weight']
                upper_bound = schedule[i][j]['weight']
                self.assertEqual(lower_bound, 92)
                self.assertEqual(upper_bound, 92)
            if i == 0 and j == 5:
                lower_bound = -schedule[j][i]['weight']
                upper_bound = schedule[i][j]['weight']
                self.assertEqual(lower_bound, 96)
                self.assertEqual(upper_bound, 100)
            if i == 0 and j == 6:
                lower_bound = -schedule[j][i]['weight']
                upper_bound = schedule[i][j]['weight']
                self.assertEqual(lower_bound, 98)
                self.assertEqual(upper_bound, 106)
            if i == 1 and j == 2:
                lower_bound = -schedule[j][i]['weight']
                upper_bound = schedule[i][j]['weight']
                self.assertEqual(lower_bound, 4)
                self.assertEqual(upper_bound, 8)
            if i == 2 and j == 3:
                lower_bound = -schedule[j][i]['weight']
                upper_bound = schedule[i][j]['weight']
                self.assertEqual(lower_bound, 2)
                self.assertEqual(upper_bound, 6)
            if i == 3 and j == 4:
                lower_bound = -schedule[j][i]['weight']
                upper_bound = schedule[i][j]['weight']
                self.assertEqual(lower_bound, 0)
                self.assertEqual(upper_bound, MAX_FLOAT)
            if i == 4 and j == 5:
                lower_bound = -schedule[j][i]['weight']
                upper_bound = schedule[i][j]['weight']
                self.assertEqual(lower_bound, 4)
                self.assertEqual(upper_bound, 8)
            if i == 5 and j == 6:
                lower_bound = -schedule[j][i]['weight']
                upper_bound = schedule[i][j]['weight']
                self.assertEqual(lower_bound, 2)
                self.assertEqual(upper_bound, 6)
Beispiel #2
0
class TestFPC(unittest.TestCase):
    """ Tests the solver FullPathConsistency

    """
    logger = logging.getLogger('stn.test')

    def setUp(self):
        # Load the stn as a dictionary
        with open(STN) as json_file:
            stn_dict = json.load(json_file)

        # Convert the dict to a json string
        stn_json = json.dumps(stn_dict)

        self.stp = STP('fpc')
        self.stn = self.stp.get_stn(stn_json=stn_json)

    def test_build_stn(self):
        self.logger.info("STN: \n %s", self.stn)

        metric, minimal_network = self.stp.solve(self.stn)

        self.logger.info("Minimal STN: \n %s", minimal_network)

        completion_time = minimal_network.get_completion_time()
        makespan = minimal_network.get_makespan()
        self.logger.info("Completion time: %s ", completion_time)
        self.logger.info("Makespan: %s ", makespan)

        self.assertEqual(completion_time, 65)
        self.assertEqual(makespan, 100)

        constraints = minimal_network.get_constraints()

        for (i, j) in constraints:

            if i == 0 and j == 1:
                lower_bound = -minimal_network[j][i]['weight']
                upper_bound = minimal_network[i][j]['weight']
                self.assertEqual(lower_bound, 35)
                self.assertEqual(upper_bound, 41)
            if i == 0 and j == 2:
                lower_bound = -minimal_network[j][i]['weight']
                upper_bound = minimal_network[i][j]['weight']
                self.assertEqual(lower_bound, 41)
                self.assertEqual(upper_bound, 47)
            if i == 0 and j == 3:
                lower_bound = -minimal_network[j][i]['weight']
                upper_bound = minimal_network[i][j]['weight']
                self.assertEqual(lower_bound, 45)
                self.assertEqual(upper_bound, 51)
            if i == 0 and j == 4:
                lower_bound = -minimal_network[j][i]['weight']
                upper_bound = minimal_network[i][j]['weight']
                self.assertEqual(lower_bound, 90)
                self.assertEqual(upper_bound, 96)
            if i == 0 and j == 5:
                lower_bound = -minimal_network[j][i]['weight']
                upper_bound = minimal_network[i][j]['weight']
                self.assertEqual(lower_bound, 96)
                self.assertEqual(upper_bound, 102)
            if i == 0 and j == 6:
                lower_bound = -minimal_network[j][i]['weight']
                upper_bound = minimal_network[i][j]['weight']
                self.assertEqual(lower_bound, 100)
                self.assertEqual(upper_bound, 106)
            if i == 1 and j == 2:
                lower_bound = -minimal_network[j][i]['weight']
                upper_bound = minimal_network[i][j]['weight']
                self.assertEqual(lower_bound, 6)
                self.assertEqual(upper_bound, 12)
            if i == 2 and j == 3:
                lower_bound = -minimal_network[j][i]['weight']
                upper_bound = minimal_network[i][j]['weight']
                self.assertEqual(lower_bound, 4)
                self.assertEqual(upper_bound, 10)
            if i == 3 and j == 4:
                lower_bound = -minimal_network[j][i]['weight']
                upper_bound = minimal_network[i][j]['weight']
                self.assertEqual(lower_bound, 39)
                self.assertEqual(upper_bound, 51)
            if i == 4 and j == 5:
                lower_bound = -minimal_network[j][i]['weight']
                upper_bound = minimal_network[i][j]['weight']
                self.assertEqual(lower_bound, 6)
                self.assertEqual(upper_bound, 12)
            if i == 5 and j == 6:
                lower_bound = -minimal_network[j][i]['weight']
                upper_bound = minimal_network[i][j]['weight']
                self.assertEqual(lower_bound, 4)
                self.assertEqual(upper_bound, 10)
Beispiel #3
0
class TestSREA(unittest.TestCase):
    """ Tests the solver Static Robust Execution

    """
    logger = logging.getLogger('stn.test')

    def setUp(self):
        # Load the stn as a dictionary
        with open(STN) as json_file:
            pstn_dict = json.load(json_file)

        # Convert the dict to a json string
        pstn_json = json.dumps(pstn_dict)

        self.stp = STP('srea')
        self.stn = self.stp.get_stn(stn_json=pstn_json)

    def test_build_stn(self):
        self.logger.info("PSTN: \n %s", self.stn)

        self.logger.info("Getting GUIDE...")
        alpha, guide_stn = self.stp.solve(self.stn)
        self.logger.info("GUIDE")
        self.logger.info(guide_stn)
        self.logger.info("Alpha: %s ", alpha)

        completion_time = guide_stn.get_completion_time()
        makespan = guide_stn.get_makespan()
        self.logger.info("Completion time: %s ", completion_time)
        self.logger.info("Makespan: %s ", makespan)

        self.assertEqual(completion_time, 60)
        self.assertEqual(makespan, 97)

        expected_alpha = 0.0
        self.assertEqual(alpha, expected_alpha)

        constraints = guide_stn.get_constraints()

        for (i, j) in constraints:

            if i == 0 and j == 1:
                lower_bound = -guide_stn[j][i]['weight']
                upper_bound = guide_stn[i][j]['weight']
                self.assertEqual(lower_bound, 37)
                self.assertEqual(upper_bound, 38)
            if i == 0 and j == 2:
                lower_bound = -guide_stn[j][i]['weight']
                upper_bound = guide_stn[i][j]['weight']
                self.assertEqual(lower_bound, 41)
                self.assertEqual(upper_bound, 47)
            if i == 0 and j == 3:
                lower_bound = -guide_stn[j][i]['weight']
                upper_bound = guide_stn[i][j]['weight']
                self.assertEqual(lower_bound, 42)
                self.assertEqual(upper_bound, 54)
            if i == 0 and j == 4:
                lower_bound = -guide_stn[j][i]['weight']
                upper_bound = guide_stn[i][j]['weight']
                self.assertEqual(lower_bound, 92)
                self.assertEqual(upper_bound, 94)
            if i == 0 and j == 5:
                lower_bound = -guide_stn[j][i]['weight']
                upper_bound = guide_stn[i][j]['weight']
                self.assertEqual(lower_bound, 96)
                self.assertEqual(upper_bound, 102)
            if i == 0 and j == 6:
                lower_bound = -guide_stn[j][i]['weight']
                upper_bound = guide_stn[i][j]['weight']
                self.assertEqual(lower_bound, 97)
                self.assertEqual(upper_bound, 109)
            if i == 1 and j == 2:
                lower_bound = -guide_stn[j][i]['weight']
                upper_bound = guide_stn[i][j]['weight']
                self.assertEqual(lower_bound, 0)
                self.assertEqual(upper_bound, 47)
            if i == 2 and j == 3:
                lower_bound = -guide_stn[j][i]['weight']
                upper_bound = guide_stn[i][j]['weight']
                self.assertEqual(lower_bound, 0)
                self.assertEqual(upper_bound, 61)
            if i == 3 and j == 4:
                lower_bound = -guide_stn[j][i]['weight']
                upper_bound = guide_stn[i][j]['weight']
                self.assertEqual(lower_bound, 0)
                self.assertEqual(upper_bound, 61)
            if i == 4 and j == 5:
                lower_bound = -guide_stn[j][i]['weight']
                upper_bound = guide_stn[i][j]['weight']
                self.assertEqual(lower_bound, 0)
                self.assertEqual(upper_bound, 61)
            if i == 5 and j == 6:
                lower_bound = -guide_stn[j][i]['weight']
                upper_bound = guide_stn[i][j]['weight']
                self.assertEqual(lower_bound, 0)
                self.assertEqual(upper_bound, MAX_FLOAT)