0

我有一堆字符串,它们是字典中的键,包含不等式系统:

例如“t1+t2 > 2 ^ t1 < 1 ^ t2 >= 1”

这些字符串是根据用户输入创建的,但有时系统是不可能的:

例如“t1+t3 > 2 ^ t1 <= 1 ^ t3 <= 1”。

t1 和 t3 没有可能的值来解决系统问题。如果系统不可能,我需要从字典中删除元素。

我确信对于同一个“主题”没有多重不平等。例如,不能有:

“... ^ t2 > 0 ^ t2 <= 2 ^ ...”

“... ^ 0 < t2 <= 2 ^ ...” 是可能的

如果我必须编写一些代码,我会做这样的事情,但它非常混乱,我无法获得关于如何获得结果 True 或 False 的好图片(或至少是好的图片),无论这是不可能的或可能的系统......我很确定有更好的方法来处理这个问题(可能有超过 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
    ...

有什么帮助吗?

4

0 回答 0