def test_functions_available(self): v = VDF() self.assertEqual(v.functions_available(), ['bpr'], 'VDF class returning wrong availability') self.assertEqual(v.apply_vdf, None, 'VDF is missing term') self.assertEqual(v.apply_derivative, None, 'VDF is missing term') with self.assertRaises(ValueError): v.function = 'Cubic' with self.assertRaises(AttributeError): v.apply_vdf = isinstance
def test_functions_available(self): v = VDF() self.assertEqual(v.functions_available(), ["bpr", "conical"], "VDF class returning wrong availability") self.assertEqual(v.apply_vdf, None, "VDF is missing term") self.assertEqual(v.apply_derivative, None, "VDF is missing term") with self.assertRaises(ValueError): v.function = "Cubic" with self.assertRaises(AttributeError): v.apply_vdf = isinstance
def __check_attributes(self, instance, value): if instance == "rgap_target": if not isinstance(value, float): return False, value, "Relative gap needs to be a float" if isinstance(self.assignment, LinearApproximation): self.assignment.rgap_target = value elif instance == "max_iter": if not isinstance(value, int): return False, value, "Number of iterations needs to be an integer" if isinstance(self.assignment, LinearApproximation): self.assignment.max_iter = value elif instance == "vdf": v = value.lower() if v not in all_vdf_functions: return False, value, f"Volume-delay function {value} is not available" value = VDF() value.function = v elif instance == "classes": if isinstance(value, TrafficClass): value = [value] elif isinstance(value, list): for v in value: if not isinstance(v, TrafficClass): return False, value, "Traffic classes need to be proper AssignmentClass objects" else: raise ValueError("Traffic classes need to be proper AssignmentClass objects") elif instance == "vdf_parameters": if not self.__validate_parameters(value): return False, value, f"Parameter set is not valid: {value} " elif instance in ["time_field", "capacity_field"]: if not isinstance(value, str): return False, value, f"Value for {instance} is not string" elif instance == "cores": if not isinstance(value, int): return False, value, f"Value for {instance} is not integer" elif instance == "save_path_files": if not isinstance(value, bool): return False, value, f"Value for {instance} is not boolean" if instance not in self.__dict__: return False, value, f"trafficAssignment class does not have property {instance}" return True, value, ""
def __init__(self) -> None: parameters = Parameters().parameters["assignment"]["equilibrium"] self.__dict__["rgap_target"] = parameters["rgap"] self.__dict__["max_iter"] = parameters["maximum_iterations"] self.__dict__["vdf"] = VDF() self.__dict__["classes"] = None # type: List[TrafficClass] self.__dict__["algorithm"] = None # type: str self.__dict__["vdf_parameters"] = None # type: list self.__dict__["time_field"] = None # type: str self.__dict__["capacity_field"] = None # type: str self.__dict__["assignment"] = None # type: LinearApproximation self.__dict__["capacity"] = None # type: np.ndarray self.__dict__["free_flow_tt"] = None # type: np.ndarray self.__dict__["total_flow"] = None # type: np.ndarray self.__dict__["congested_time"] = None # type: np.ndarray self.__dict__["cores"] = None # type: int
def __init__(self) -> None: parameters = Parameters().parameters["assignment"]["equilibrium"] self.__dict__["rgap_target"] = parameters["rgap"] self.__dict__["max_iter"] = parameters["maximum_iterations"] self.__dict__["vdf"] = VDF() self.__dict__["classes"] = [] # type: List[TrafficClass] self.__dict__["algorithm"] = None # type: str self.__dict__["vdf_parameters"] = None # type: list self.__dict__["time_field"] = None # type: str self.__dict__["capacity_field"] = None # type: str self.__dict__["assignment"] = None # type: LinearApproximation self.__dict__["capacity"] = None # type: np.ndarray self.__dict__["free_flow_tt"] = None # type: np.ndarray self.__dict__["total_flow"] = None # type: np.ndarray self.__dict__["congested_time"] = None # type: np.ndarray self.__dict__["cores"] = None # type: int self.__dict__["procedure_id"] = uuid4().hex self.__dict__["description"] = "" self.__dict__["procedure_date"] = str(datetime.today()) self.__dict__["steps_below_needed_to_terminate"] = 1