def generate_solution_from_serial_schedule_generation_scheme(sgs, problem): """ creates new solution object from a valid serial schedule generation scheme, which is list of tuples containing activities and corresponding modes solution will be resource feasible for renewable resources """ solution = Solution() resource_usages_in_time = collections.defaultdict(ResourceUsage.ResourceUsage) time_points = [0] for activity, mode in sgs: last_time = time_points[-1] start_time = 0 for time_unit in reversed(time_points): actual_resource_usage = copy.copy(resource_usages_in_time[time_unit]) actual_resource_usage.add_resource_usage(mode.demand) if (actual_resource_usage.is_resource_usage_greater_than_supply(problem.resources) or (activity_in_conflict_in_precedence(problem, solution, activity, time_unit))): start_time = last_time break else: last_time = time_unit solution.set_start_time_for_activity(activity, start_time, mode) ListUtilities.insert_value_to_ordered_list(time_points, start_time) ListUtilities.insert_value_to_ordered_list(time_points, start_time + mode.duration) ResourceUsage.update_resource_usages_in_time(resource_usages_in_time, mode, start_time) return solution
def generate_solution_from_serial_schedule_generation_scheme(sgs, problem): """ creates new solution object from a valid serial schedule generation scheme, which is list of tuples containing activities and corresponding modes solution will be resource feasible for renewable resources """ solution = Solution() resource_usages_in_time = collections.defaultdict( ResourceUsage.ResourceUsage) time_points = [0] for activity, mode in sgs: last_time = time_points[-1] start_time = 0 for time_unit in reversed(time_points): actual_resource_usage = copy.copy( resource_usages_in_time[time_unit]) actual_resource_usage.add_resource_usage(mode.demand) if (actual_resource_usage. is_resource_usage_greater_than_supply( problem.resources) or (activity_in_conflict_in_precedence( problem, solution, activity, time_unit))): start_time = last_time break else: last_time = time_unit solution.set_start_time_for_activity(activity, start_time, mode) ListUtilities.insert_value_to_ordered_list(time_points, start_time) ListUtilities.insert_value_to_ordered_list( time_points, start_time + mode.duration) ResourceUsage.update_resource_usages_in_time( resource_usages_in_time, mode, start_time) return solution
def generate_solution_from_serial_schedule_generation_scheme(sgs, problem): solution = Solution() resource_usages_in_time = defaultdict(ResourceUsage) time_points = [0] for activity in sgs: last_time = time_points[-1] start_time = 0 for time_unit in reversed(time_points): actual_resource_usage = copy( resource_usages_in_time[time_unit]) actual_resource_usage.add_resource_usage(activity.demand) if (actual_resource_usage. is_resource_usage_greater_than_supply( problem.resources) or (activity_in_conflict_in_precedence( problem, solution, activity, time_unit))): start_time = last_time break else: last_time = time_unit solution.set_start_time_for_activity(activity, start_time) ListUtilities.insert_value_to_ordered_list(time_points, start_time) ListUtilities.insert_value_to_ordered_list( time_points, start_time + activity.duration) update_resource_usages_in_time(resource_usages_in_time, activity, start_time) return solution
class Sego(object): def __init__(self): self.list_utilities = ListUtilities() self.application_utilities = ApplicationUtilities() @doc(ListUtilities().get_list_doc()) def list(self,target): self.list_utilities.run_list(target=target) @doc(ApplicationUtilities().get_application_doc()) def application(self,task,**kwargs): self.application_utilities.run(task=task,kwargs=kwargs)
def compare_results(req_structure, given_structure): '''Compare requested table/column structure with what's available''' # Re-Shape objects for easier comparison reqStructDict = {} for struct in req_structure: reqStructDict['{}.{}'.format(struct.Schema, struct.Table)] = struct givenStructDict = {} for struct in given_structure: givenStructDict['{}.{}'.format(struct.Schema, struct.Table)] = struct failedStructure = [] for table in reqStructDict.keys(): if table in givenStructDict.keys(): missingColumns = False for column in ListUtilities.ensureIsList( reqStructDict[table].Columns): if column not in givenStructDict[table].Columns: missingColumns = True # Fail if any columns are missing if missingColumns is True: failedStructure.append(reqStructDict[table]) # Fail if table is missing else: failedStructure.append(reqStructDict[table]) return failedStructure
def generate_solution_from_serial_schedule_generation_scheme(sgs, problem): solution = Solution() resource_usages_in_time = defaultdict(ResourceUsage) time_points = [0] for activity in sgs: last_time = time_points[-1] start_time = 0 for time_unit in reversed(time_points): actual_resource_usage = copy(resource_usages_in_time[time_unit]) actual_resource_usage.add_resource_usage(activity.demand) if (actual_resource_usage.is_resource_usage_greater_than_supply(problem.resources) or (activity_in_conflict_in_precedence(problem, solution, activity, time_unit))): start_time = last_time break else: last_time = time_unit solution.set_start_time_for_activity(activity, start_time) ListUtilities.insert_value_to_ordered_list(time_points, start_time) ListUtilities.insert_value_to_ordered_list(time_points, start_time + activity.duration) update_resource_usages_in_time(resource_usages_in_time, activity, start_time) return solution
def parse_xml(xml_path): '''Parse XML files in path for <tableStructure> nodes''' requestedStructure = [] for content in XMLDataCrawler.getXMLData(xml_path, 'tableStructure', 'table'): a = TableStructure() a.Schema = str(content['@schema']) a.Table = str(content['@name']) if 'column' in content.keys(): for column in ListUtilities.ensureIsList(content['column']): a.Columns.append(column) requestedStructure.append(a) return requestedStructure
def test_insert_value_to_ordered_list(self): l = [1,3,4,5] ListUtilities.insert_value_to_ordered_list(l, 2) self.assertEqual(l, [1,2,3,4,5], "2 should be inserted after 1") l = [1,4,5,6] ListUtilities.insert_value_to_ordered_list(l, 4) self.assertEqual(l, [1,4,5,6], "list should remain unchanged") l = [0] ListUtilities.insert_value_to_ordered_list(l, 4) self.assertEqual(l, [0,4], "list should be updated properly")
def __init__(self): self.list_utilities = ListUtilities() self.application_utilities = ApplicationUtilities() self.controller_utilities = ControllerUtilities()
def __init__(self): self.list_utilities = ListUtilities() self.application_utilities = ApplicationUtilities()