@@ -58,11 +58,13 @@ def charToBin(char):
5858def binsToFormula (bin ):
5959 results = []
6060 for bi in bin :
61+ # print(bi, binToFormula(bi))
6162 results .append (binToFormula (bi ))
6263 return results
6364
6465def binToFormula (bin ):
65- if bin != None and len (bin ) == countChild :
66+ # if bin != None and len(bin) == countChild:
67+ if bin != None and len (bin ) > 0 :
6668 results = []
6769 i = 0
6870 for bi in bin :
@@ -75,6 +77,38 @@ def binToFormula(bin):
7577 else :
7678 return None
7779
80+ def formulasToBin (formulas ):
81+ results = []
82+ for formula in formulas :
83+ results .append (formulaToBin (formula ))
84+ return results
85+
86+ def formulaToBin (formula ):
87+ if formula != None and len (formula ) > 0 :
88+ results = []
89+ i = 0
90+ print (";;;" ,formula )
91+ for f in formula :
92+ if i == 0 and f .startswith ("y" ):
93+ print ("1/insert y" )
94+ results .append (0 ) # x
95+ elif i == 0 and f .startswith ("z" ):
96+ results .append (0 ) # x
97+ results .append (0 ) # y
98+ print ("2/insert x" )
99+ print ("2/insert y" )
100+ elif i == 1 and f .startswith ("z" ):
101+ results .append (0 ) # y
102+ print ("3/insert y" )
103+ print ("f" , f )
104+ if f .endswith ("'" ):
105+ results .append (0 )
106+ else :
107+ results .append (1 )
108+ i = i + 1
109+ return results
110+ return None
111+
78112def binToFormulaOld (bin ):
79113 if bin == [0 ,0 ,0 ]:
80114 return ["x'" ,"y'" ,"z'" ]
@@ -185,16 +219,24 @@ def evalFormula(formula, binaries):
185219 # print(binaries)
186220 print ("Solving g for binaries:" )
187221 results = []
222+ print (binaries )
188223 for binary in binaries :
189224 newFormula = formula
190225 i = 0
191226 # newFormula=newFormula.replace("x", str(binary[0]))
192227 # newFormula=newFormula.replace("y", str(binary[1]))
193228 # newFormula=newFormula.replace("z", str(binary[2]))
229+ # print(newFormula)
194230 for alpha in alphas :
195- newFormula = newFormula .replace (alpha + "'" , str (binary [i ]))
231+ # print("===>", alpha, binary[i])
232+ # print("-->", newFormula)
233+ if binary [i ] == 0 :
234+ newFormula = newFormula .replace (alpha + "'" , str (1 ))
235+ elif binary [i ] == 1 :
236+ newFormula = newFormula .replace (alpha + "'" , str (0 ))
196237 newFormula = newFormula .replace (alpha , str (binary [i ]))
197238 i = i + 1
239+ # print(" >", newFormula)
198240
199241 calcFormula = evalAlgorithm (newFormula , formula , binary )
200242 calcFormula = 1 if calcFormula >= 1 else 0
@@ -322,6 +364,8 @@ def filterGArray(g):
322364number = "0167"
323365number = "1247"
324366number = "25"
367+ print ("Enter number: " )
368+ number = input ()
325369countChild = 3
326370numberLength = len (number )
327371alphas = string .ascii_lowercase
@@ -372,107 +416,49 @@ def filterGArray(g):
372416 subscriptions .append (subscription )
373417
374418print ("Subscriptions: " , subscriptions )
375- g = subscriptionsFilter (subscriptions )
376- print ("g, SubscriptionsAll: " , g )
377-
378- if g != None and len (g ) != 0 :
419+ subscriptionsFilter = subscriptionsFilter (subscriptions )
420+ print ("SubscriptionsAll: " , subscriptionsFilter )
421+ if subscriptionsFilter == None or len (subscriptionsFilter ) == 0 :
422+ g = binaries
423+ print ("g: " , g )
424+ print ("gFormula: " , binsToFormula (g ))
425+ else :
426+ g = subscriptionsFilter
379427 commonSubscriptions = commonValues (g )
380428 print ("commonSubscriptions: " , commonSubscriptions )
381429 if commonSubscriptions != None :
430+ print ("newG did changed using removeValue()..." )
382431 newG = [commonSubscriptions , [removeValue (g , commonSubscriptions )]]
432+ print ("newG: " , newG )
433+ newG = filterGArray (newG )
434+ print ("newGFilter: " , newG )
383435 else :
384436 newG = g
385- print ("newG: " , newG )
386- newG = filterGArray (newG )
387- print ("newG: " , newG )
388- if newG != None and len (newG ) != 0 :
389- gFormula = toFormula (newG )
390- print ("gFormula: " , gFormula ) #It's $g formula
391-
392- gValues = evalFormula (gFormula , binaries )
393- gValuesCount = len (gValues )
394-
395- print ("gValues: " , gValues )
396- print ("gValuesCount: " , gValuesCount )
397- print ("Compare gValuesCount with binariesLength: " , gValuesCount , "??" , binariesLength )
398-
399- if gValuesCount == binariesLength :
400- print ("\t They are equal!" )
401- g = newG
402- elif gValuesCount < binariesLength :
403- print ("\t binariesLength is bigger then gValuesCount." )
404- g = newG
405- print ("Diff two array:" )
406- print ("\t subscriptions1: " , binaries )
407- print ("\t subscriptions2: " , gValues )
408- nonSubscribersAll = nonSubscribers (binaries , gValues )
409- print ("NonSubscribers: " , nonSubscribersAll )
410- nonSubscribersAllFormula = binsToFormula (nonSubscribersAll )
411- print ("nonSubscribersAllFormula: " , nonSubscribersAllFormula )
412- g = g + nonSubscribersAllFormula
413- else :
414- print ("Error: binariesLength is more then gValuesCount and we not except it!" )
415- sys .exit (- 1 )
416-
417-
437+ print ("newG: " , newG )
438+
439+ gFormula = toFormula (newG )
440+ print ("newGFormula: " , gFormula ) #It's $g formula
441+
442+ gValues = evalFormula (gFormula , binaries )
443+ gValuesCount = len (gValues )
444+ print ("Compare gValuesCount with binariesLength: " , gValuesCount , "??" , binariesLength )
445+
446+ if gValuesCount == binariesLength :
447+ print ("\t They are equal!" )
448+ g = formulasToBin (newG )
449+ elif gValuesCount < binariesLength :
450+ print ("\t binariesLength is bigger then gValuesCount." )
451+ g = newG
452+ print ("Diff two array:" )
453+ print ("\t subscriptions1: " , binaries )
454+ print ("\t subscriptions2: " , gValues )
455+ nonSubscribersAll = nonSubscribers (binaries , gValues )
456+ print ("NonSubscribers: " , nonSubscribersAll )
457+ nonSubscribersAllFormula = binsToFormula (nonSubscribersAll )
458+ print ("nonSubscribersAllFormula: " , nonSubscribersAllFormula )
459+ g = g + nonSubscribersAllFormula
418460 else :
419- print ("newG formula is empty!" )
420- else :
421- subscriptions
422- print ("g formula is empty!" )
423- # if subscriptionsAll != None and len(subscriptionsAll) != 0:
424- # subscriptionsAllFormula=toFormula(subscriptionsAll)
425- # print("SubscriptionsAllFormula: ", subscriptionsAllFormula) #It's $g formula
426-
427- # gValues=evalFormula(subscriptionsAllFormula, binaries)
428- # gValuesCount=len(gValues)
429-
430- # print("gValues: ", gValues)
431- # print("gValuesCount: ", gValuesCount)
432- # print("Compare gValuesCount with binariesLength: ", gValuesCount, "??", binariesLength)
433- # g=[]
434- # if gValuesCount == binariesLength:
435- # print("\tThey are equal!")
436- # g=subscriptionsAll
437- # elif gValuesCount < binariesLength:
438- # print("\tbinariesLength is bigger then gValuesCount.")
439- # g=subscriptionsAll
440- # print("Diff two array:")
441- # print("\tsubscriptions1: ", binaries)
442- # print("\tsubscriptions2: ", gValues)
443- # nonSubscribersAll=nonSubscribers(binaries, gValues)
444- # print("NonSubscribers: ", nonSubscribersAll)
445- # nonSubscribersAllFormula=binsToFormula(nonSubscribersAll)
446- # print("nonSubscribersAllFormula: ", nonSubscribersAllFormula)
447- # g=g + nonSubscribersAllFormula
448- # else:
449- # print("Error: binariesLength is more then gValuesCount and we not except it!")
450- # sys.exit(-1)
451-
452- # print("g: ", g)
453- # gFormula=toFormula(g)
454- # print("gFormula: ", gFormula)
455- # gNormalize=normalize(g)
456- # print("gNormalize: ", gNormalize)
457- # gNormalizeSubscriptions=subscriptionsOfFormulas(gNormalize)
458- # print("gNormalizeSubscriptions: ", gNormalizeSubscriptions)
459- # gNormalizeSubscriptionsCount=len(gNormalizeSubscriptions)
460- # print("gNormalizeSubscriptionsCount: ", gNormalizeSubscriptionsCount)
461- # gNormalizeSubscriptionsFilter=removeNoneArrays(gNormalizeSubscriptions)
462- # print("gNormalizeSubscriptionsFilter: ", gNormalizeSubscriptionsFilter)
463-
464- # gNormalizeSubscriptionsFilterDublicate=removeDublicateValue(gNormalizeSubscriptionsFilter)
465- # print("gNormalizeSubscriptionsFilterDublicate: ", gNormalizeSubscriptionsFilterDublicate)
466-
467- # if gNormalizeSubscriptionsCount == 0:
468- # print("Error: Cannot draw this graph!")
469- # sys.exit(-1)
470-
471- # g=gNormalizeSubscriptionsFilterDublicate
472-
473- # else:
474- # print("Not need to calc g formula!")
475- # g=subscriptionsAll
476-
477- # graph=g
478- # print("Graph: ", graph)
461+ print ("Error: binariesLength is more then gValuesCount and we not except it!" )
462+ sys .exit (- 1 )
463+
464+ print ("graph: " , g )
0 commit comments