Ejemplo n.º 1
0
    def multiSearch(self):
        def mygen2():
            c = {
                "rad_w": 1,
                "ecc_w": -0.5,
                "area_w": 1,
                "length_w": 1,
                "ratio": 1,
                "d": 1,
            }
            area_w = [0.1, 0.5, 1, 1.5, 2]
            length_w = [0.1, 0.5, 1, 1.5, 2]
            for aw in area_w:
                c['area_w'] = aw
                yield c
            c['area_w'] = 1
            for lw in length_w:
                c['length_w'] = lw
                yield c

        def mygenprov():
            c = {
                "rad_w": 1,
                "ecc_w": 0,
                "area_w": 0,
                "length_w": 0,
                "ratio": 1,
                "d": 1,
            }
            yield c

        def mygen():
            c = {
                "rad_w": 0.5,
                "ecc_w": -0.5,
                "area_w": 1,
                "length_w": 1,
                "ratio": 1,
                "d": 1,
            }
            ecc_w = [-0.1]
            length_ratio = [1.2, 1.5, 2, 0.75, 0.5]
            d_ratios = [0.75, 1.25, 1.5]
            for w in ecc_w:
                c['ecc_w'] = w
                yield c

            c['ecc_w'] = -0.5

        count = 1
        for consts in mygenprov():
            dirname = 'savedtry/constraints' + str(count) + '/'
            if not os.path.exists(dirname):
                os.makedirs(dirname)
            open(
                dirname + 'constraints.txt',
                'w').write("Torsional radius weight: " + str(consts['rad_w']) +
                           "Eccentricity weight: " + str(consts['ecc_w']) +
                           "\nShear Wall length weight: " +
                           str(consts['length_w']) +
                           "\nShear Wall cover area weight: " +
                           str(consts['area_w']))
            self.constraints = consts
            self.reinit_skeletons()
            self.solutions = {}
            for levelSkeleton in self.skeletonLevels[::-1]:
                level = self.skeletonLevelsHash[levelSkeleton]
                prevs = [
                    self.solutions[self.levelsHash[p]].levelSkeleton
                    for p in level.getUpperLevels()
                    if self.levelsHash[p] in self.solutions
                ]
                print("PREVS LENGTH IS", len(prevs))
                if len(prevs):
                    levelSkeleton.copyLevelsVoiles(prevs)
                i = self.skeletonLevels.index(levelSkeleton)
                solution = search(levelSkeleton,
                                  filename="level" + str(i),
                                  constraints=self.constraints)
                self.solutions[levelSkeleton] = solution
            self.saveSkeletons(dirname)
            count += 1
Ejemplo n.º 2
0
    def multiSearch(self, diroot='saved', layers=None, iterations=1):
        def mygen2():
            c = {
                "rad_w": 0,
                "ecc_w": -0.5,
                "area_w": 1,
                "length_w": 1,
                "ratio": 1,
                "d": 1,
            }
            area_w = [0.1, 0.5, 1, 1.5, 2]
            length_w = [0.1, 0.5, 1, 1.5, 2]
            ecc_w = [-0.1, -1, -1.5]
            for aw in area_w:
                c['area_w'] = aw
                yield c
            c['area_w'] = 1
            for lw in length_w:
                c['length_w'] = lw
                yield c
            c['length_w'] = 1
            for ew in ecc_w:
                c['ecc_w'] = ew
                yield c

        def mygenprov():
            c = {
                "rad_w": 0,
                "ecc_w": -0.5,
                "area_w": 1,
                "length_w": 1,
                "ratio": 1,
                "d": 1,
            }
            yield c

        def mygen():
            c = {
                "rad_w": 0,
                "ecc_w": -0.5,
                "area_w": 1,
                "length_w": 1,
                "ratio": 1,
                "d": 1,
            }
            area_w = [1.5, 2, 4]
            d_ratios = [0.25, 0.5, 0.75]
            for d in d_ratios:
                c['d'] = d
                for w in area_w:
                    c['area_w'] = w
                    yield c

        count = 1
        for consts in mygenprov():
            dirname = diroot + '/constraints' + str(count) + '/'
            if not os.path.exists(dirname):
                os.makedirs(dirname)
            open(
                dirname + 'constraints.txt',
                'w').write("Torsional radius weight: " + str(consts['rad_w']) +
                           "\nEccentricity weight: " + str(consts['ecc_w']) +
                           "\nShear Wall length weight: " +
                           str(consts['length_w']) +
                           "\nShear Wall cover area weight: " +
                           str(consts['area_w']) + "\nArea Distance ratio: " +
                           str(consts['d']))
            for iteration in range(0, iterations):
                dirIt = dirname + 'iteration' + str(iteration + 1) + '/'
                self.constraints = consts
                self.reinit_skeletons()
                self.solutions = {}
                if layers is None:
                    skeletonLevels = self.skeletonLevels
                else:
                    skeletonLevels = self.skeletonLevels[:layers]
                for levelSkeleton in skeletonLevels[::-1]:
                    level = self.skeletonLevelsHash[levelSkeleton]
                    prevs = [
                        self.solutions[self.levelsHash[p]].levelSkeleton
                        for p in level.getUpperLevels()
                        if self.levelsHash[p] in self.solutions
                    ]
                    print(("PREVS LENGTH IS", len(prevs)))
                    if len(prevs):
                        levelSkeleton.copyLevelsVoiles(prevs)
                    i = self.skeletonLevels.index(levelSkeleton)
                    solution = search(levelSkeleton,
                                      filename="level" + str(i),
                                      constraints=self.constraints)
                    self.solutions[levelSkeleton] = solution

                print((self.solutions))
                self.saveSkeletons(dirIt, consts, layers)
            count += 1
Ejemplo n.º 3
0
    def multiSearch(self):
        def mygen2():
            c = {
                "rad_w": 0,
                "ecc_w": -0.5,
                "area_w": 3,
                "length_w": 1,
                "ratio": 1,
                "d": 1,
            }
            area_w = [0.1, 0.5, 1, 1.5, 2]
            length_w = [0.1, 0.5, 1, 1.5, 2]
            for aw in area_w:
                c['area_w'] = aw
                yield c
            c['area_w'] = 1
            for lw in length_w:
                c['length_w'] = lw
                yield c

        def mygenprov():
            c = {
                "rad_w": 0,
                "ecc_w": 0.5,
                "area_w": 5,
                "length_w": 0,
                "ratio": 1,
                "d": 1,
            }
            yield c

        def mygen():
            c = {
                "rad_w": 1,
                "ecc_w": -0.5,
                "area_w": 1,
                "length_w": 5,
                "ratio": 1,
                "d": 1,
            }
            area_w = [1.5, 2, 3, 4, 10]
            d_ratios = [0.25, 0.5, 0.75]
            for d in d_ratios:
                c['d'] = d
                for w in area_w:
                    c['area_w'] = w
                    yield c
                    break
                break

        count = 1
        for consts in mygenprov():
            dirname = 'savedWrong/constraints' + str(count) + '/'
            if not os.path.exists(dirname):
                os.makedirs(dirname)
            open(
                dirname + 'constraints.txt',
                'w').write("Torsional radius weight: " + str(consts['rad_w']) +
                           "Eccentricity weight: " + str(consts['ecc_w']) +
                           "\nShear Wall length weight: " +
                           str(consts['length_w']) +
                           "\nShear Wall cover area weight: " +
                           str(consts['area_w']))
            self.constraints = consts
            self.init_skeletons(ind=1)
            self.solutions = {}
            froot = dirname + '/'
            if not os.path.exists(froot):
                os.makedirs(froot)
            f = open(froot + 'Scores.txt', 'w')
            scores = []
            for levelSkeleton in self.skeletonLevels[::-1]:
                if self.skeletonLevels.index(levelSkeleton) == len(
                        self.skeletonLevels) - 1:
                    self.ColumnsVoileSkeleton = WallSkeleton.ColumnToVoile(
                        self.Columns, levelSkeleton.wallSkeletons)
                    levelSkeleton.addColumnsAsVoiles(self.ColumnsVoileSkeleton)

                level = self.skeletonLevelsHash[levelSkeleton]
                prevs = [
                    self.solutions[self.levelsHash[p]].levelSkeleton
                    for p in level.getUpperLevels()
                    if self.levelsHash[p] in self.solutions
                ]
                print(("PREVS LENGTH IS", len(prevs)))

                if len(prevs):
                    levelSkeleton.copyLevelsVoiles(prevs)
                i = self.skeletonLevels.index(levelSkeleton)
                distributionScore = 0.6
                SYM = 0
                # overlapscore = 1
                j = 1

                w = [0.5, 1, 1.5, 2]
                combs = []
                [combs.append(p) for p in itertools.product(w, repeat=4)]
                # combs = [[1,0.5,1,2]]
                l = 1
                for comb in combs:
                    print('Progress', l / len(combs) * 100, '%', '_', l)
                    l = l + 1
                    # while j==1 :

                    solution = None

                    for i in range(1):

                        if self.skeletonLevels.index(levelSkeleton) == len(
                                self.skeletonLevels) - 1:
                            while True:
                                try:
                                    solution = search(
                                        levelSkeleton,
                                        filename="leve" + str(i),
                                        constraints=self.constraints,
                                        Comb=comb)
                                except:
                                    continue
                                break
                        else:
                            LS = self.skeletonLevels[len(self.skeletonLevels) -
                                                     1]
                            solution = self.solutions[LS]
                        fitness = solution.getFitness(
                            constraints=self.constraints)
                        scores.append([
                            fitness['sym'], fitness['area'], fitness['rad'],
                            fitness['distribution'], fitness['totalScore']
                        ])
                        distributionScore = fitness['distribution']
                        SYM = fitness['sym']
                        print('result gave ', distributionScore, SYM)
                        # j = 2

                    # overlapscore = fitness['overlapped']
                    # print("here condition out", distributionScore, overlapscore )
                self.solutions[levelSkeleton] = solution
            for l in range(len(scores)):
                if (l % 2) == 0:
                    score = scores[l]
                    f.write(
                        str(score[0]) + "/" + str(score[1]) + "/" +
                        str(score[2]) + "/" + str(score[3]) + "/" +
                        str(score[4]) + "\n")
            self.saveSkeletons(dirname)
            count += 1