Beispiel #1
0
    def onStar(self):
        self.base = BaseDeConnaissance(self.path)
        self.tbResolution.setText("")
        EtatInit = self.base.faits[0].predicat
        graphe = Graph(EtatInit)
        nouedFermées = []
        nouedOuverts = [EtatInit]
        i = 0

        # Graph construction
        while nouedOuverts:

            nouedCourant = nouedOuverts.pop(0)
            nouedFermées.append(nouedCourant)
            self.base.faits = nouedCourant
            possibleConclusions = genererConclusionUnifies(
                self.base.regles, nouedCourant)

            for conclusion in possibleConclusions:
                graphe.addEdge(nouedCourant, conclusion)
                if not exist(conclusion, nouedFermées) and not exist(
                        conclusion, nouedOuverts):
                    nouedOuverts.append(conclusion)
            i += 1

        etatFinal = self.txEtatFinal.toPlainText()
        test = Predicat.extractPredicat(etatFinal)
        solution = 'chemin\n'

        result, parcours = graphe.a_star_search(graphe.V, test)
        for chem in parcours:
            print(chem)
            solution += str(chem) + '\n'
        self.tbResolution.setText("")
        self.tbResolution.setText(solution)
        self.textBrowser.setText("")
        self.textBrowser.setText(graphe.trace)
Beispiel #2
0
    possibleConclusions = genererConclusionUnifies(base.regles, nouedCourant)

    for conclusion in possibleConclusions:
        graphe.addEdge(nouedCourant, conclusion)
        if not exist(conclusion, nouedFermées) and not exist(
                conclusion, nouedOuverts):
            nouedOuverts.append(conclusion)
    i += 1

for key in graphe.graph:
    print("*********")
    print("Sommet: ", key.nom, '(', key.vals, ')')
    print("Values")
    for val in graphe.graph[key]:
        print("fils: ", val.nom, '(', val.vals, ')')

test = Predicat("cruchesAetB", ['4', '2'])
chemin = []
print("=========rechercheProfendeurLimiteIteratif===========")
print(graphe.rechercheProfendeurLimiteIteratif(graphe.V, test, 10, chemin))
chemin = algorithmService.prepareChemin(
    chemin, graphe.V
)  # Function that modifies the path in order to get it in a good format
for chem in chemin:
    print(chem)

print("=======a_star_search============")
result, parcours = graphe.a_star_search(graphe.V, test)
for chem in parcours:
    print(chem)