def testRankingRules(): print('*-------- Testing Ranking Rules -------') t = RandomPerformanceTableau(numberOfActions=5) t.save() t.showPerformanceTableau() scores = t.computeWeightedAveragePerformances(isNormalized=True, lowValue=0.0, highValue=20.0) ranking = [] for x in t.actions: ranking.append((scores[x], x)) ranking.sort(reverse=True) print(ranking) g = BipolarOutrankingDigraph(t) g.exportGraphViz() gcd = CoDualDigraph(g) gcd.exportGraphViz() #gcd._computeRankedPairsOrder(Debug=True) #print(gcd._computeRankedPairsOrder()) gcd.computeKemenyOrder(Debug=True) print(gcd.computeKemenyRanking(seed=1, sampleSize=500)) gcd.computeSlaterOrder(Debug=True) print(gcd.computeSlaterOrder(isProbabilistic=False, seed=1, sampleSize=500))
def testLPDCount(): print( '*---- test large performance differences count and denotation ----*') T = RandomPerformanceTableau( commonThresholds=[(10.0, 0.0), (20.0, 0.0), (50.0, 0.0), (60.0, 0.0)]) G = BipolarOutrankingDigraph(T, hasBipolarVeto=True) G.showRelationTable(hasLPDDenotation=True)
def testCoDualDigraph(): print('*---- test codual digraph -----*') t = RandomCBPerformanceTableau(numberOfActions=13, numberOfCriteria=7) g = BipolarOutrankingDigraph(t) g.save('testcodual') gasym = AsymmetricPartialDigraph(g) gasym.exportGraphViz('gtest') gcd = CoDualDigraph(g) gcd.exportGraphViz('gcdtest')
def testHTMLMaps(): from outrankingDigraphs import BipolarOutrankingDigraph from randomPerfTabs import RandomCBPerformanceTableau from linearOrders import CopelandOrder t1 = Random3ObjectivesPerformanceTableau(numberOfActions=10, seed=1) g = BipolarOutrankingDigraph(t1, Normalized=True) cop = CopelandOrder(g) print(g._htmlRelationMap(cop.copelandRanking)) print(g._htmlRelationMap(Colored=False))
def testPerformanceTableau(): print('==>> Testing Performance Tableau instantiation') t = RandomPerformanceTableau() t.showAll() t.save('testSavePerftab') tb = PerformanceTableau('testSavePerftab') tb.showAll() g = BipolarOutrankingDigraph(tb) g.showAll()
def testPairwiseClusterComparison(): print('*----- test paiwise cluster comparisons ----*') t = RandomCBPerformanceTableau(numberOfActions=10) g = BipolarOutrankingDigraph(t) actionsList = [x for x in list(g.actions.keys())] K1 = actionsList[5:] K2 = actionsList[:5] print(g.valuationdomain) g.computePairwiseClusterComparison(K1, K2, Debug=True)
def testStandardConversion(): print('==>> Testing 2 Standard conversion') t = cR3ObjPT(numberOfActions=10, seed=1) print(t) gi = IntegerBipolarOutrankingDigraph(t, Threading=True, nbrCores=4) print(gi) gi.showRelationTable() tstd = t.convert2Standard() g = BipolarOutrankingDigraph(tstd) print(g) g.showRelationTable()
def testBigDataConversion(): print('==>> Testing 2 Big Data conversion') t = R3ObjPT(numberOfActions=10, seed=1) print(t) g = BipolarOutrankingDigraph(t, Threading=True, nbrCores=4) print(g) g.showRelationTable() tbd = t.convert2BigData() gi = IntegerBipolarOutrankingDigraph(tbd) print(gi) gi.showRelationTable()
def testcIntegerOutrankingDigraph(): print('==>> Testing IntegerBipolarOutrankingDigraph instantiation') tc = cR3ObjPT(seed=1) print(tc) gi = IntegerBipolarOutrankingDigraph(tc, Threading=True, nbrCores=4) print(gi) gi.showRelationTable() tcstd = tc.convert2Standard() g = BipolarOutrankingDigraph(tcstd) print(g) g.showRelationTable()
def testCoceDigraph(): print('*----- test rxperimental CoceDigraph class ----*') from digraphs import _CoceDigraph t = RandomCBPerformanceTableau(numberOfActions=10) g = BipolarOutrankingDigraph(t) coceg = _CoceDigraph(g, Comments=True) coceg.computeChordlessCircuits() print(coceg.computeDeterminateness()) print(coceg.computeDeterminateness()) print(g.computeBipolarCorrelation(coceg)) print(g.computeOrdinalCorrelation(coceg))
def testStrongComponentsCollapsedDigraph(): print('*---- test strong components collapsed digraph -----*') t = RandomCBPerformanceTableau(numberOfActions=13, numberOfCriteria=7) g = BipolarOutrankingDigraph(t) gscc = StrongComponentsCollapsedDigraph() gscc = StrongComponentsCollapsedDigraph(g) gscc.showActions() gscc.showRelationTable() gscc.exportGraphViz()
def testEstimateRankingCorrelation(): print('====> Testing estimateRankingCorrelation') MP = True nbrActions = 1000 tp = Random3ObjectivesPerformanceTableau(numberOfActions=nbrActions, seed=100) bg1 = PreRankedOutrankingDigraph( tp, CopyPerfTab=True, quantiles=4, quantilesOrderingStrategy='optimal', componentRankingRule='NetFlows', LowerClosed=True, minimalComponentSize=1, Threading=MP, nbrOfCPUs=8, #tempDir='.', nbrOfThreads=8, Comments=True, Debug=False, save2File='testbgMP') seed = 1 sampleSize = 100 import random random.seed(seed) actionKeys = [x for x in bg1.actions] sample = random.sample(actionKeys, sampleSize) print(sample) print(bg1.boostedRanking) preRankedSample = [] for x in bg1.boostedRanking: if x in sample: preRankedSample.append(x) print(preRankedSample) ptp = PartialPerformanceTableau(tp, sample) from outrankingDigraphs import BipolarOutrankingDigraph pg = BipolarOutrankingDigraph(ptp, Normalized=True) print(pg.computeRankingCorrelation(preRankedSample)) print(bg1.estimateRankingCorrelation(sampleSize, seed))
def testXMCDA2SaveReadPerformanceTableau(): print('*==>> save and read XMCDA-2.0 PerformanceTableau instances ----*') #t = RandomS3PerformanceTableau(numberOfActions=5,numberOfCriteria=15,weightDistribution="random",weightScale=(1,13),IntegerWeights=True,commonThresholds=[(5.0,0.0),(10.0,0.0),(50.0,0.0),(60.0,0.0)],RandomCoalitions=True,commonMode=['beta',0.5,None]) #t.showAll() t = RandomCBPerformanceTableau(numberOfActions=5, numberOfCriteria=7, weightDistribution="random", weightScale=(1, 7), IntegerWeights=True) t.saveXMCDA2('test') g = BipolarOutrankingDigraph(t) g.showRelationTable() t1 = XMCDA2PerformanceTableau('test') g1 = BipolarOutrankingDigraph(t1) g1.showRelationTable()
def testCBPerformanceTableau(): print('*==>> random CB Performance Tableaux ------------*') t = RandomCBPerformanceTableau(numberOfActions=10,\ commonPercentiles={'ind':5,'pref':10,'veto':95},\ weightDistribution="random",\ weightScale=[1,2],\ IntegerWeights=True,\ commonMode=["normal",50.0,25.0]) t.showCriteria(Debug=False) g = BipolarOutrankingDigraph(t) g.exportGraphViz() #t.showPerformanceTableau() g.showRelationTable()
def testLinearVotingBallots(): print("*==>> testing linear voting profiles ----*") lvp = RandomLinearVotingProfile(numberOfVoters=100, numberOfCandidates=10, WithPolls=True, partyRepartition=0.6, other=0.1, seed=None) lvp.save() lvp = LinearVotingProfile('templinearprofile') lvp.showLinearBallots() print(lvp.computeRankAnalysis()) lvp.showRankAnalysisTable(Debug=True) print(lvp.computeBordaScores()) print(lvp.computeBordaWinners()) c = MajorityMarginsDigraph(lvp) c.exportGraphViz() print(c.computeChordlessCircuits()) lvp.save2PerfTab() t = PerformanceTableau('votingPerfTab') from outrankingDigraphs import BipolarOutrankingDigraph g = BipolarOutrankingDigraph(t) lvp.showHTMLVotingHeatmap() print(c.computeCopelandRanking())
def testSparseOutrankingDigraph(): print('==>> Testing SparseOutrankingDigraph instantiation') MP = True t0 = time() tp = Random3ObjectivesPerformanceTableau(numberOfActions=100, BigData=True) print(time() - t0) print(total_size(tp.evaluation)) bg1 = PreRankedOutrankingDigraph(tp, quantiles=10, quantilesOrderingStrategy='average', LowerClosed=True, minimalComponentSize=1, Threading=MP, Debug=False) print(bg1.computeDecompositionSummaryStatistics()) bg1.showDecomposition() print(bg1) t0 = time() g = BipolarOutrankingDigraph(tp, Normalized=True, Threading=MP) print(time() - t0) print(total_size(g)) t0 = time() print( "Big outranking digraph's correlation with standard outranking digraph" ) print(bg1.computeOrdinalCorrelation(g, Debug=False)) print(time() - t0) nf = bg1.computeBoostedOrdering(orderingRule="NetFlows") preordering1 = bg1.ordering2Preorder(nf) print(nf, preordering1) print( 'Boosted Netflows ranking correlation with complete outranking relation' ) print(g.computeOrdinalCorrelation(g.computePreorderRelation(preordering1))) ko = bg1.computeBoostedOrdering(orderingRule="Kohler") preordering2 = bg1.ordering2Preorder(ko) print(ko, preordering2) print( 'Boosted Kohler ranking correlation with complete outranking relation') print(g.computeOrdinalCorrelation(g.computePreorderRelation(preordering2)))
def testFullRandomOutrankingDigraph(): print('*==>> testing full random outranking Digraphs ----*') t = FullRandomPerformanceTableau() #t = RandomCBPerformanceTableau() t.showAll() g = BipolarOutrankingDigraph(t) g.showCriteria() g.showPerformanceTableau() g.showEvaluationStatistics() ## g.showStatistics() g.showVetos(realVetosOnly=True) print('criteria significance concentration: ', g.computeWeightsConcentrationIndex())
from sortingDigraphs import QuantilesSortingDigraph ###Q1### print('-' * 10, 'Question1', '-' * 10) # load the tableau tab = PerformanceTableau('perfTab_28') print(tab) tab.showHTMLPerformanceHeatmap(Correlations=True, ndigits=0, colorLevels=9) input("Press Enter to continue...") ###Q2### print('-' * 10, 'Question2', '-' * 10) from outrankingDigraphs import BipolarOutrankingDigraph as BipolarOD # bipolar outranking digraph bipolar = BipolarOD(tab) # compute chordless circuits bipolar.computeChordlessCircuits() # show computed chordless circuits bipolar.showChordlessCircuits() input("Press Enter to continue...") ###Q3### print('-' * 10, 'Question3', '-' * 10) #Copeland Ranking cop = CopelandOrder(bipolar) cop_corr = bipolar.computeOrdinalCorrelation(cop).get('correlation') print(f'Correlation of Copeland order {cop_corr}') #Kohler Ranking koh = KohlerOrder(bipolar)
def fwrite(string, file): with open(file, 'w') as f: f.write(string) pt = XMCDA2PerformanceTableau('project_2') for ct in ['Eco', 'Soc', 'Env']: printline() print('RUBIS Best Choice Recommendation from {} point of view'.format(ct)) printline() criterias = [c for c, val in pt.criteria.items() if ct in val['name']] ppt = PartialPerformanceTableau(pt,criteriaSubset=criterias) partial_digraph = BipolarOutrankingDigraph(ppt) html_heatmap = ppt.htmlPerformanceHeatmap(colorLevels=5) fwrite(html_heatmap, make_path(ct+"_heatmap.html")) html_relationtable = partial_digraph.htmlRelationTable(isColored=True) fwrite(html_relationtable, make_path(ct+"_bipolar_adj_matrix.html")) condorcet_winners = partial_digraph.condorcetWinners() printline() print("Condorcet winners for {} -> {}".format(ct, condorcet_winners)) printline() weak_condorcet_winners = partial_digraph.weakCondorcetWinners() printline() print("Weak Condorcet winners for {} -> {}".format(ct, weak_condorcet_winners))
#!/usr/bin/env python3 __author__ = "Maciej Zurad" __email__ = "*****@*****.**" __license__ = "GPL" import os from perfTabs import * from outrankingDigraphs import BipolarOutrankingDigraph make_path = lambda x: os.path.join('..', 'report', 'figures', x.lower()) printline = lambda: print(80 * '-') pt = XMCDA2PerformanceTableau('project_2') full_digraph = BipolarOutrankingDigraph(pt) printline() print('Ranking') printline() print('Transitivity degree {}'.format( full_digraph.computeTransitivityDegree())) printline() print('Chorless circuits') full_digraph.computeChordlessCircuits() full_digraph.showChordlessCircuits() printline() print('') from linearOrders import CopelandOrder cop = CopelandOrder(full_digraph) print('The Copeland ranking')
pt.showCriteria() print('') printline() print('Actions') printline() pt.showActions() print('') printline() print('Statistics') printline() pt.showStatistics() print('') full_digraph = BipolarOutrankingDigraph(pt) html_heatmap = pt.htmlPerformanceHeatmap(RankingRule='Kohler') fwrite(html_heatmap, make_path("full_heatmap.html")) html_relationtable = full_digraph.htmlRelationTable(isColored=True) fwrite(html_relationtable, make_path("full_bipolar_adj_matrix.html")) weak_condorcet_winners = full_digraph.weakCondorcetWinners() printline() print("Weak Condorcet winners from a multi-objectives point of view -> {}". format(weak_condorcet_winners)) printline() condorcet_winners = full_digraph.condorcetWinners() printline()