示例#1
0
 def test_level_mark_basics(self):
     G = nx.DiGraph()
     G.add_nodes_from(range(8))
     G.add_edges_from([(0, 1), (0, 4), (1, 2), (2, 3), (4, 5), (5, 2),
                       (5, 6), (6, 7), (7, 3)])
     ConstructionOrdering.markLevels(G)
     self.assertEqual(G.node[0][ConstructionOrdering.kAttrNameNodeLevel], 0)
     self.assertEqual(G.node[1][ConstructionOrdering.kAttrNameNodeLevel], 1)
     self.assertEqual(G.node[2][ConstructionOrdering.kAttrNameNodeLevel], 3)
     self.assertEqual(G.node[3][ConstructionOrdering.kAttrNameNodeLevel], 5)
     self.assertEqual(G.node[4][ConstructionOrdering.kAttrNameNodeLevel], 1)
     self.assertEqual(G.node[5][ConstructionOrdering.kAttrNameNodeLevel], 2)
     self.assertEqual(G.node[6][ConstructionOrdering.kAttrNameNodeLevel], 3)
     self.assertEqual(G.node[7][ConstructionOrdering.kAttrNameNodeLevel], 4)
     self.assertEqual(
         G.node[0][ConstructionOrdering.kAttrNameNodeAfterLength], 5)
     self.assertEqual(
         G.node[1][ConstructionOrdering.kAttrNameNodeAfterLength], 2)
     self.assertEqual(
         G.node[2][ConstructionOrdering.kAttrNameNodeAfterLength], 1)
     self.assertEqual(
         G.node[3][ConstructionOrdering.kAttrNameNodeAfterLength], 0)
     self.assertEqual(
         G.node[4][ConstructionOrdering.kAttrNameNodeAfterLength], 4)
     self.assertEqual(
         G.node[5][ConstructionOrdering.kAttrNameNodeAfterLength], 3)
     self.assertEqual(
         G.node[6][ConstructionOrdering.kAttrNameNodeAfterLength], 2)
     self.assertEqual(
         G.node[7][ConstructionOrdering.kAttrNameNodeAfterLength], 1)
     routes = ConstructionOrdering.getCriticalWays(G)
     self.assertEqual(routes, [[0, 4, 5, 6, 7, 3]])
示例#2
0
 def test_relative_nodes(self):
     G = nx.DiGraph()
     G.add_nodes_from(range(12))
     G.add_edges_from([(0, 3), (0, 4), (1, 4), (1, 5), (2, 6), (2, 7),
                       (3, 8), (4, 9), (5, 10), (6, 10), (7, 11)])
     relative1 = ConstructionOrdering.getRelativeNodes(G, 3)
     relative2 = ConstructionOrdering.getRelativeNodes(G, 4)
     self.assertTrue(
         len(relative1) == 4 and 0 in relative1 and 4 in relative1
         and 8 in relative1 and 9 in relative1)
     self.assertTrue(
         len(relative2) == 7 and 0 in relative2 and 1 in relative2
         and 3 in relative2 and 5 in relative2 and 8 in relative2
         and 9 in relative2 and 10 in relative2)
示例#3
0
    def test_mult_ordering_noerror(self):
        filePath = os.path.dirname(os.path.abspath(__file__))

        with open(
                os.path.join(
                    os.path.join(
                        os.path.split(
                            os.path.split(
                                os.path.split(
                                    os.path.split(filePath)[0])[0])[0])[0],
                        "TestData"), "testModelDataWithOneCrane.json"),
                "r") as dataFile:
            dataFile.seek(0, 0)
            data = json.loads(dataFile.read())
            if not "modelData" in data or not "cranes" in data:
                self.fail("Bad json implemented")
            parser = AdvanceSteelModelParser()
            pm = parser.ParseProjectModel(data[ec.TagCraneOptModelData])
            cranes = [TowerCraneData(data[ec.TagCraneOptCranes][0])] * 3
            sd = SiteData(pm, cranes)

            # Build model bars dependency graph
            BarDependencyChecker.buildDependencyGraph(sd)
            order = ConstructionOrdering.GetConstructionOrderMult(
                sd.dependencies, list(sd.Bars.values()), 3)
示例#4
0
    def test_clustered_ordering_noerror(self):
        c = KMeansBasedBarsDivision()
        filePath = os.path.dirname(os.path.abspath(__file__))

        with open(
                os.path.join(
                    os.path.join(
                        os.path.split(
                            os.path.split(
                                os.path.split(
                                    os.path.split(filePath)[0])[0])[0])[0],
                        "TestData"), "testModelDataWithOneCrane.json"),
                "r") as dataFile:
            dataFile.seek(0, 0)
            data = json.loads(dataFile.read())
            if not "modelData" in data or not "cranes" in data:
                self.fail("Bad json implemented")
            parser = AdvanceSteelModelParser()
            pm = parser.ParseProjectModel(data[ec.TagCraneOptModelData])
            cranes = [TowerCraneData(data[ec.TagCraneOptCranes][0])] * 3
            sd = SiteData(pm, cranes)
            centers = [
                np.array([bar.CenterPoint.X, bar.CenterPoint.Y])
                for bar in pm.SteelAnalyticalModel.Bars.values()
            ]
            c.ProhibitedRegion = sd.ModelPolygon
            c.Radiuses = [cr.maxLength for cr in cranes]
            res = c.FindCenters(centers, 3)
            # Build model bars dependency graph
            BarDependencyChecker.buildDependencyGraph(sd)
            order = ConstructionOrdering.GetConstructionOrderClustered(
                sd.dependencies, list(sd.Bars.values()), res[2])
示例#5
0
def calc_model_buildordermult():
    """Generates pre-order for building whole structure with multiple cranes data"""
    # Check whether model data is in input
    if not request.json or not ec.TagCraneOptModelData in request.json:
        abort(400)

    # Get arguments
    numCranes = 1
    if ec.ArgConstrOrderNumFlows in request.args:
        numCranes = int(request.args.get(ec.ArgConstrOrderNumFlows, 1))

    # Parse project model from JSON
    client = ""
    if ec.ArgCraneOptClient in request.args:
        client = request.args.get(ec.ArgCraneOptClient,
                                  ec.ValCommonClientAdvanceSteel)
    parser = eutils.GetParserByClientType(client,
                                          ec.ValCommonClientAdvanceSteel)
    pm = parser.ParseProjectModel(request.json[ec.TagCraneOptModelData])
    modelData = SiteData(pm, [])

    # Build model bars dependency graph
    BarDependencyChecker.buildDependencyGraph(modelData)
    PanelDependencyChecker.buildDependencyGraph(modelData)

    # Get construction order usin the graph
    res = ConstructionOrdering.GetConstructionOrderMult(
        modelData.dependencies, modelData.ConstructionObjects.values(),
        numCranes)

    # Return order
    return jsonify({ec.OutTagConstrOrderOrder: res}), 200
示例#6
0
 def test_construction_order(self):
     G = nx.DiGraph()
     G.add_nodes_from(range(12))
     G.add_edges_from([(0, 1), (0, 4), (1, 2), (2, 3), (4, 5), (5, 2),
                       (5, 6), (6, 7), (6, 8), (7, 3), (8, 3), (9, 4),
                       (3, 10)])
     order = ConstructionOrdering.getConstructionOrder(G, [])
     self.assertEqual(order, [0, 9, 4, 5, 1, 6, 2, 8, 7, 11, 3, 10])
示例#7
0
    def test_dependent_sets(self):
        G = nx.DiGraph()
        G.add_nodes_from(range(9))
        G.add_edges_from([(0, 1), (0, 4), (1, 2), (2, 3), (4, 5), (5, 2),
                          (5, 6), (6, 7), (6, 8), (7, 3), (8, 3)])
        ConstructionOrdering.markChildrenCount(G)
        self.assertEqual(
            G.node[0][ConstructionOrdering.kAttrNameNodeNumOfChildren], 2)
        self.assertEqual(
            G.node[1][ConstructionOrdering.kAttrNameNodeNumOfChildren], 1)
        self.assertEqual(
            G.node[2][ConstructionOrdering.kAttrNameNodeNumOfChildren], 1)
        self.assertEqual(
            G.node[3][ConstructionOrdering.kAttrNameNodeNumOfChildren], 0)
        self.assertEqual(
            G.node[4][ConstructionOrdering.kAttrNameNodeNumOfChildren], 1)
        self.assertEqual(
            G.node[5][ConstructionOrdering.kAttrNameNodeNumOfChildren], 2)
        self.assertEqual(
            G.node[6][ConstructionOrdering.kAttrNameNodeNumOfChildren], 2)
        self.assertEqual(
            G.node[7][ConstructionOrdering.kAttrNameNodeNumOfChildren], 1)
        self.assertEqual(
            G.node[8][ConstructionOrdering.kAttrNameNodeNumOfChildren], 1)

        ConstructionOrdering.markDependentCount(G)
        self.assertEqual(
            G.node[0][ConstructionOrdering.kAttrNameNodeDependentSetSize], 8)
        self.assertEqual(
            G.node[1][ConstructionOrdering.kAttrNameNodeDependentSetSize], 2)
        self.assertEqual(
            G.node[2][ConstructionOrdering.kAttrNameNodeDependentSetSize], 1)
        self.assertEqual(
            G.node[3][ConstructionOrdering.kAttrNameNodeDependentSetSize], 0)
        self.assertEqual(
            G.node[4][ConstructionOrdering.kAttrNameNodeDependentSetSize], 6)
        self.assertEqual(
            G.node[5][ConstructionOrdering.kAttrNameNodeDependentSetSize], 5)
        self.assertEqual(
            G.node[6][ConstructionOrdering.kAttrNameNodeDependentSetSize], 3)
        self.assertEqual(
            G.node[7][ConstructionOrdering.kAttrNameNodeDependentSetSize], 1)
        self.assertEqual(
            G.node[8][ConstructionOrdering.kAttrNameNodeDependentSetSize], 1)
示例#8
0
 def test_priorities(self):
     G = nx.DiGraph()
     G.add_nodes_from(range(12))
     G.add_edges_from([(0, 1), (0, 4), (1, 2), (2, 3), (4, 5), (5, 2),
                       (5, 6), (6, 7), (6, 8), (7, 3), (8, 3), (9, 4),
                       (3, 10)])
     ConstructionOrdering.setOrderPriorities(G)
     self.assertAlmostEqual(
         G.node[0][ConstructionOrdering.kAttrNameNodePriority], 1.0)
     self.assertAlmostEqual(
         G.node[1][ConstructionOrdering.kAttrNameNodePriority], 0.3)
     self.assertAlmostEqual(
         G.node[2][ConstructionOrdering.kAttrNameNodePriority], 0.135)
     self.assertAlmostEqual(
         G.node[3][ConstructionOrdering.kAttrNameNodePriority],
         0.03333333333333333)
     self.assertAlmostEqual(
         G.node[4][ConstructionOrdering.kAttrNameNodePriority],
         0.6666666666666667)
     self.assertAlmostEqual(
         G.node[5][ConstructionOrdering.kAttrNameNodePriority],
         0.4666666666666666)
     self.assertAlmostEqual(
         G.node[6][ConstructionOrdering.kAttrNameNodePriority], 0.25)
     self.assertAlmostEqual(
         G.node[7][ConstructionOrdering.kAttrNameNodePriority],
         0.09999999999999999)
     self.assertAlmostEqual(
         G.node[8][ConstructionOrdering.kAttrNameNodePriority],
         0.09999999999999999)
     self.assertAlmostEqual(
         G.node[9][ConstructionOrdering.kAttrNameNodePriority], 0.9)
     self.assertAlmostEqual(
         G.node[10][ConstructionOrdering.kAttrNameNodePriority],
         0.008333333333333333)
     self.assertAlmostEqual(
         G.node[11][ConstructionOrdering.kAttrNameNodePriority], 0.09)
示例#9
0
def calc_model_buildordercluster():
    """Generates pre-order for building whole structure with clustering bars between multiple cranes"""
    # Check whether model data is in input
    if not request.json or not ec.TagCraneOptModelData in request.json or not ec.TagCraneOptCranes in request.json:
        abort(400)

    # Parse project model from JSON
    client = ""
    if ec.ArgCraneOptClient in request.args:
        client = request.args.get(ec.ArgCraneOptClient,
                                  ec.ValCommonClientAdvanceSteel)
    parser = eutils.GetParserByClientType(client,
                                          ec.ValCommonClientAdvanceSteel)
    pm = parser.ParseProjectModel(request.json[ec.TagCraneOptModelData])
    cranes = [
        eutils.GetCraneByType(crane)
        for crane in request.json[ec.TagCraneOptCranes]
    ]
    modelData = SiteData(pm, cranes)

    # Build model bars dependency graph
    BarDependencyChecker.buildDependencyGraph(modelData)
    PanelDependencyChecker.buildDependencyGraph(modelData)

    # Do bars clustering
    from Optimization.Clustering.KMeansBasedBarsDivision import KMeansBasedBarsDivision
    clusterer = KMeansBasedBarsDivision()
    centers = [
        np.array([bar.CenterPoint.X, bar.CenterPoint.Y])
        for bar in pm.SteelAnalyticalModel.Bars.values()
    ]
    clusterer.ProhibitedRegion = modelData.ModelPolygon
    clusterer.Radiuses = [cr.maxLength for cr in cranes]
    resClustering = clusterer.FindCenters(centers, len(cranes))

    # Get construction order usin the graph
    res = ConstructionOrdering.GetConstructionOrderClustered(
        modelData.dependencies, list(modelData.ConstructionObjects.values()),
        resClustering[2])

    # Return order
    return jsonify({ec.OutTagConstrOrderOrder: res}), 200
示例#10
0
def calc_model_buildordermult_bo():
    """not working"""
    """Generates pre-order for building whole structure with multiple cranes data"""
    import json

    # default installation time 1.5 minutes
    installationTime = 1.5

    # load the base JSON
    baseModel = None
    reader = codecs.getreader("utf-8")
    file_name = os.path.normpath(
        "c:/dev/BuildOptimizer/PrefabOptimizationServer/PrefabOptimizationServer/Tests/model.json"
    )

    with open(file_name, encoding='utf-8-sig') as data_file:
        baseModel = json.loads(data_file.read())
    # Get arguments
    numCranes = 1

    # Parse project model from JSON
    client = ""
    parser = eutils.GetParserByClientType(client,
                                          ec.ValCommonClientAdvanceSteel)
    pm = parser.ParseProjectModel(baseModel[ec.TagCraneOptStructureData])
    modelData = SiteData(pm, [])

    # Build model bars dependency graph
    BarDependencyChecker.buildDependencyGraph(modelData)
    PanelDependencyChecker.buildDependencyGraph(modelData)

    # Get construction order usin the graph
    res = ConstructionOrdering.GetConstructionOrderMult(
        modelData.dependencies, modelData.ConstructionObjects.values(),
        numCranes)

    # Return order
    return jsonify({ec.OutTagConstrOrderOrder: res}), 200
示例#11
0
    def MapFusionToKB(kbTasks, fusionTasks):
        """Map kb and fusion tasks to each other"""
        res = {}

        if not kbTasks or not "tasks" in kbTasks or not fusionTasks:
            return res

        # Order tasks obtained from KB using graph structure
        tasksOrder = nx.DiGraph()
        mapNumber = 1
        for task in kbTasks["tasks"]:
            tasksOrder.add_node(task[Task.__kTagName])
            tasksOrder.node[task[Task.__kTagName]] = {
                "task": task,
                "mapNumber": mapNumber
            }
            mapNumber += 1
        for task in kbTasks["tasks"]:
            if Task.__kTagAfterTask in task[Task.__kTagProperties] and len(
                    task[Task.__kTagProperties][Task.__kTagAfterTask]) > 0:
                for t in task[Task.__kTagProperties][Task.__kTagAfterTask]:
                    tasksOrder.add_edge(t, task[Task.__kTagName])

        seen = []

        # Go over task groups in fusion array
        for fgroup in fusionTasks.items():
            # Tasks are under the non-empty array values
            if isinstance(fgroup[1], list) and len(fgroup[1]) > 0:
                baseItem = fgroup[1][0]
                ruleGroups = []

                # Find rulegroups for fusion task group
                for g in Task.__kMappingRules:
                    applicableRules = 0
                    for rule in g:
                        if rule[Task.__kLookForKey] in baseItem:
                            applicableRules += 1
                    if len(g) == applicableRules:
                        ruleGroups.append(g)

                # Map tasks from fusion tasks group to tasks from kb
                for ruleGroup in ruleGroups:
                    nodes = [
                        node for node in tasksOrder if len([
                            rule for rule in ruleGroup
                            if rule[Task.__kKeyValue].lower() in node.lower()
                        ])
                    ]
                    if nodes:
                        for item in fgroup[1]:
                            nodeSet = []
                            for node in nodes:
                                for rule in ruleGroup:
                                    if Task.__kKBToolKey in rule:
                                        if Task.__CheckKBTaskKeyForMatch(
                                                tasksOrder.node[node]["task"],
                                                rule[Task.__kKBToolKey],
                                                item[rule[Task.__kKeyValue]]):
                                            nodeSet.append(node)
                                    else:
                                        nodeSet.append(node)
                            for node in nodeSet:
                                if not node in res:
                                    res[node] = {"orderMark": 0, "tasks": []}
                                res[node]["tasks"].append(item)

        # Mark graph levels
        from Optimization.Order.ConstructionOrdering import ConstructionOrdering
        ConstructionOrdering.markLevels(tasksOrder)

        for item in res.items():
            item[1]["orderMark"] = tasksOrder.node[item[0]]["level"]

        return res