不等式のシステムを含む辞書のキーである一連の文字列があります。
例: "t1+t2 > 2 ^ t1 < 1 ^ t2 >= 1"
これらの文字列はユーザー入力に基づいて作成されますが、システムによっては不可能な場合があります。
例: "t1+t3 > 2 ^ t1 <= 1 ^ t3 <= 1"。
システムを解決する t1 と t3 の可能な値はありません。システムが不可能な場合は、辞書から要素を削除する必要があります。
同じ「主題」に関して複数の不平等がないことは確かです。たとえば、次のことはできません。
「... ^ t2 > 0 ^ t2 <= 2 ^ ...」
しかし
「... ^ 0 < t2 <= 2 ^ ...」が可能
何らかのコードを書かなければならない場合、私はこのようなことをしますが、それは非常に面倒で、不可能であるかどうかにかかわらず、結果の真または偽を取得する方法について良い図 (または少なくとも良い図) を得ることができません。または可能なシステム...そして、問題を処理するより良い方法があると確信しています(3つ以上の変数が存在する可能性がありますが、3でそれを行う方法を理解していれば、nでそれを行うことができると思います) :
def logical(string):
h = string.split(" ^ ")
count = [0,0,0]
for i in [1,2,3]:
for j in h:
if "t"+str(i) in h:
count[i-1] += 1
...
#consider the elements of h that contain "t"+1 if count of
#that variable is bigger than 1
#and for those who contain the sum of two or more
#variables check the number of "words" (can be 3 or 5). Then
#check if elements in position 1 and/or 3 are "<=" or "<" or
#">=" or ">" ... and compare it to the element of h that
#contains instead ... veeeery long and mechanical
...
助けはありますか?