Exemplo n.º 1
0
 def rule(self, numberOfExtensions = 1,verbose = False):
     if verbose:
         print "\n--------------------------------------------"
         print "prepare to apply {} new rules to the diagram:".format(numberOfExtensions)
     self.ExtensionRequests = []
     for rule in self.Rules:
         CD = rule.CD 
         for hom in HomomorphismIterator(CD,self.diagram):
             if rule.name=="ComposeRule":
                 ER = ComposeRequest(rule,hom)
                 if not ER.useful:
                     continue
             else:
                 ER = ExtensionRequest(rule,hom)
             
             if iscontainedin(ER,self.implemented):
                 continue
             if not iscontainedin(ER,self.ExtensionRequests):
                 self.ExtensionRequests.append(ER)
     if verbose:
         print "{} new extension requests generated".format(len(self.ExtensionRequests))
         print "prioritise extension requests"
     
     if self.ExtensionRequests==[]:#nothing new to conclude
         return False
     
     sortedExtensionRequests = sorted(self.ExtensionRequests,key = self.Prioritiser)
     
     ruleNumber = 0
     while ruleNumber<numberOfExtensions:
         #if there are no more extension requests, terminate
         if not sortedExtensionRequests:
             break
         
         extensionRequest = sortedExtensionRequests.pop(0)
         if extensionRequest in self.implemented:
             continue
         
         if verbose:
             print "\n\n apply new Rule:"
             print extensionRequest.rule.name
             print extensionRequest.hom
             print "with priority value {}\n"\
                     .format(self.Prioritiser(extensionRequest))
         
         extensionRequest.implement()
         self.implemented.append(extensionRequest)
         ruleNumber+=1                  
     
     if verbose:
         print "applied {} new rules".format(ruleNumber)
     return True
Exemplo n.º 2
0
def reprWithoutZeros(D):
    str_ = "Diagram with the following data"
    str_+= "| Objects:\n| "
    str_+="\n| ".join(str(o) for o in D.Objects)
    str_+="\n\n| Morphisms by Commutativity class:\n| "
    printed = []
    for s in D.MorphismList:
        quot = s.equivalenceClass()
        if isMorphismZero(quot):
            continue
        if iscontainedin(quot, printed):
            continue
        
        str_+="\n| "+str(quot)
        printed.append(quot)
    return str_