Пример #1
0
    def test_small(self):
        configuration = Configuration('''3
4
Russia,Brazil,Argentina
Germany,Italy,England
France,Iran,Mexico
USA,Japan,Australia
AFC:Iran,Japan,Australia
CAF:None
OFC:None
CONCACAF:USA,Mexico
CONMEBOL:Brazil,Argentina
UEFA:France,Germany,Italy,England,Russia''')
        minConflictSolver = MinConflictSolver()
        for pot in configuration.pots.values():
            minConflictSolver.add_variable(pot, range(0, configuration.group))
            minConflictSolver.add_constraint(AllDifferentConstraint(), pot)
        for team_name, teams in configuration.teams.iteritems():
            if team_name == 'UEFA':
                minConflictSolver.add_constraint(AtMostTwoConstraint(), teams)
            else:
                minConflictSolver.add_constraint(AllDifferentConstraint(),
                                                 teams)
        solution = minConflictSolver.get_solution()
        output = defaultdict(list)
        if solution is not None:
            for team_name, group in solution.iteritems():
                output[group].append(team_name)
        print(solution_generator(solution, configuration.group))
        result_tester(configuration, solution)
Пример #2
0
 def test_share(self):
     for filename in os.listdir('share_case'):
         start = int(round(time.time() * 1000))
         if filename.endswith(".txt"):
             with open("share_case/" + filename) as f:
                 print("processing file: " + filename)
                 file_lines = f.read()
                 configuration = Configuration(file_lines)
                 minConflictSolver = MinConflictSolver()
             for pot in configuration.pots.values():
                 minConflictSolver.add_variable(
                     pot, range(0, configuration.group))
                 minConflictSolver.add_constraint(AllDifferentConstraint(),
                                                  pot)
             for team_name, teams in configuration.teams.iteritems():
                 if team_name == 'UEFA':
                     minConflictSolver.add_constraint(
                         AtMostTwoConstraint(), teams)
                 else:
                     minConflictSolver.add_constraint(
                         AllDifferentConstraint(), teams)
             solution = minConflictSolver.get_solution()
             if solution is None:
                 print(filename + ' NONE!!')
             result_tester(configuration, solution)
             with open("share_case/output_" + filename + '.out',
                       'w') as the_file:
                 the_file.write(
                     solution_generator(solution, configuration.group))
                 the_file.write("\nreading, running, checking time: " +
                                str(int(round(time.time() * 1000)) -
                                    start) + ' ms')
             continue
         else:
             continue
Пример #3
0
    def test_case3(self):
        configuration = Configuration('''8
4
Russia,Germany,Brazil,Portugal,Argentina,Belgium,Poland,France
Spain,Peru,Switzerland,England,Colombia,Mexico,Uruguay,Croatia
Denmark,Iceland,Costa Rica,Sweden,Tunisia,Egypt,Senegal,Iran
Serbia,Nigeria,Australia,Japan,Morocco,Panama,South Korea,Saudi Arabia
AFC:South Korea,Saudi Arabia,Iran,Japan,Australia
CAF:Tunisia,Egypt,Senegal,Morocco,Nigeria
CONCACAF:Mexico,Panama,Costa Rica
CONMEBOL:Brazil,Argentina,Uruguay,Colombia,Peru
UEFA:France,Germany,England,Russia,Portugal,Belgium,Poland,Switzerland,Croatia,Denmark,Iceland,Serbia,Spain,Sweden
OFC:None''')
        minConflictSolver = MinConflictSolver()
        for pot in configuration.pots.values():
            minConflictSolver.add_variable(pot, range(0, configuration.group))
            minConflictSolver.add_constraint(AllDifferentConstraint(), pot)
        for team_name, teams in configuration.teams.iteritems():
            if team_name == 'UEFA':
                minConflictSolver.add_constraint(AtMostTwoConstraint(), teams)
            else:
                minConflictSolver.add_constraint(AllDifferentConstraint(),
                                                 teams)
        solution = minConflictSolver.get_solution()
        output = defaultdict(list)
        if solution is not None:
            for team_name, group in solution.iteritems():
                output[group].append(team_name)
        print(solution_generator(solution, configuration.group))
        result_tester(configuration, solution)
Пример #4
0
    def test_huge(self):
        configuration = Configuration('''27
25
AHL,WSS,SGB
ZCD,QMQ,AAQ,PLR,VDM
GOL,PXW,FIP
HRJ,YVF
JFV,SDQ
IQG,IHZ,LEN,PKP
QBF,XAO,LFS,GAH
WKL,LVD,JQE,NDT,QZK,REW,HJN
KLV,ROP,NXT,IEV,KRI,YRA,BUS,KCW
TBY,RPW,CPP
RMP,PGU
FSW,DGY,FRY,ADH,AOD
ZLX,GTE
ITJ,KDP,GPM,SFB,YIS
DXU,WBM,UVT,TAN,BSN,SMS,AIL
QNY,JQH,XCZ
PVW,BDD,FRE,VTB,CTZ,JJE,NIY,LKR,HHC
EUE,TNN,PSL
QZS,GGQ,ZUR,JXZ,RPJ
FIV,OFZ,RWF,WIB,BJS,UDP,DWE
HNH,GMA,ASE,ZTQ,LIS,XYE,JFP,WWR,XZJ
LPD,DVC,LYV,LXK
IND,YJW,GUO,SQI,ZLU,LZA
TIT,RGM,DED,BSK,KIP
AXU,F*G,EES,BEP,YWM,KJK,ZYO,TAD,PYO
AFC:EES,QNY,YJW,FSW,RPW,UVT,SQI,ZUR,VTB,TIT,BEP,LPD,SMS,LFS,ZLU,LEN,RPJ,LZA
CAF:IND,GOL,GPM,WBM,LIS,PXW,BSN,BJS,YWM,YRA,JQH,DVC,LYV,ADH,PLR,SGB,FIP,LXK
OFC:KLV,ZCD,ASE,KDP,QZS,RMP,TAN,JQE,NXT,WSS,IEV,JFP,DGY,BSK,KCW,CPP,HHC
CONCACAF:FIV,DXU,GMA,QMQ,EUE,OFZ,ZLX,ZTQ,AAQ,GUO,RWF,AHL,FRE,NDT,JJE,WWR,DED,SFB,VDM,YVF,GAH,PGU,AOD
CONMEBOL:AXU,PVW,IQG,HRJ,BDD,XAO,IHZ,XYE,QZK,KRI,KJK,BUS,NIY,FRY,REW,ZYO,LKR,TAD,HJN,GTE,YIS,PSL,DWE
UEFA:HNH,F*G,TBY,ITJ,QBF,WKL,LVD,ROP,WIB,GGQ,TNN,CTZ,UDP,JFV,RGM,JXZ,SDQ,PKP,AIL,XCZ,XZJ,KIP,PYO'''
                                      )
        minConflictSolver = MinConflictSolver()
        for pot in configuration.pots.values():
            minConflictSolver.add_variable(pot, range(0, configuration.group))
            minConflictSolver.add_constraint(AllDifferentConstraint(), pot)
        for team_name, teams in configuration.teams.iteritems():
            if team_name == 'UEFA':
                minConflictSolver.add_constraint(AtMostTwoConstraint(), teams)
            else:
                minConflictSolver.add_constraint(AllDifferentConstraint(),
                                                 teams)
        for _ in range(100):
            solution = minConflictSolver.get_solution()
            if solution is not None:
                break
            print("restart======")
        output = defaultdict(list)
        if solution is not None:
            for team_name, group in solution.iteritems():
                output[group].append(team_name)
        print(solution_generator(solution, configuration.group))
        result_tester(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
        minConflictSolver = MinConflictSolver()
        for pot in configuration.pots.values():
            minConflictSolver.add_variable(pot, range(0, configuration.group))
            minConflictSolver.add_constraint(AllDifferentConstraint(), pot)
        for team_name, teams in configuration.teams.iteritems():
            if team_name == 'UEFA':
                minConflictSolver.add_constraint(AtMostTwoConstraint(), teams)
            else:
                minConflictSolver.add_constraint(AllDifferentConstraint(),
                                                 teams)
        for _ in range(100):
            solution = minConflictSolver.get_solution()
            if solution is not None:
                break
            print("restart======")
        output = defaultdict(list)
        if solution is not None:
            for team_name, group in solution.iteritems():
                output[group].append(team_name)
        print(solution_generator(solution, configuration.group))
        result_tester(configuration, solution)
Пример #6
0
 def test_dump_none(self):
     solutions = {'team1': 1, 'team2': 2, 'team3': 3}
     print(solution_generator(solutions, 4))
     self.assertEqual('Yes\nteam1\nteam2\nteam3\nNone',
                      solution_generator(solutions, 4))