Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. from sys import argv
  2.  
  3. script, variable, constraint, procedure = argv
  4.  
  5. variableList = ()
  6. constraintList = []
  7. answer = {}
  8.  
  9. variableFile = open(variable, "r")
  10. constraintFile = open(constraint, "r")
  11. procedureFile = open(procedure, "r")
  12.  
  13. with open(variable, 'r') as variableFile:
  14. varNum = sum(1 for line in open(variable))
  15. for x in range(0, varNum):
  16. line = variableFile.readline()
  17. line = line.replace(':', '')
  18. line = line.split()
  19. if not line:
  20. continue
  21. answer[line[0]] = line[1:]
  22. variableList = variableList + (line[0],)
  23. print(variableList)
  24. # print(variableFile.read())
  25. # answer = answer.replace(":", "")
  26. print(answer)
  27.  
  28. with open(constraint, 'r') as constraintFile:
  29. conNum = sum(1 for line in open(constraint))
  30. varTuple = ()
  31. for x in range(0, conNum):
  32. line = constraintFile.readline()
  33. varTuple = line.split()
  34. constraintList.append(varTuple)
  35. # print(constraintList[0])
  36. # print(constraintList)
  37.  
  38. with open(procedure, 'r') as consistencyFile:
  39. print(consistencyFile.read())
  40.  
  41. def backtrack(assignments, unassignedVariableList, constraintList):
  42. if complete(unassignedVariableList):
  43. return assignments
  44. selectedVariable =
  45.  
  46.  
  47. def complete(unassignedVariableList):
  48. return len(unassignedVariableList) == 0
  49.  
  50. # Variable with the fewest values available
  51. def mostConstrainedVariable(unassignedVariableList):
  52. return min(unassignedVariableList.keys(), key=lambda k: len(unassignedVariableList[k]))
  53.  
  54. # Value that eliminates the least amount of other values when assigned
  55. def leastConstrainingValue(unassignedVariableList, assignmentList, selectedVariable, constraintList):
  56. def countValues(variables):
  57. return sum((len(variables[v]) for v in unassignedVariableList if v != selectedVariable))
  58. def valuesDeleted(value):
  59. assignmentList[selectedVariable] = [value]
  60. updatedValues = countValues(enforceConsistency(assignmentList, unassignedVariableList, constraintList))
  61. del assignmentList[selectedVariable]
  62. return updatedValues
  63.  
  64.  
  65. #def consistencyCheck(assignmentList, unassignedVariableList, constraintList):
  66. # def removeInconsistency(head, tail, constraint, variableList):
  67. # validTails = [t for t in variableList[tail] if any((constraint(h, t) for h in variables[head]))]
  68. # invalidValues = len(variableList[tail]) != len(valid_tail_values)
  69. # variableList[tail] = validTails
  70. # return invalidValues
  71.  
  72. #def newConstraint()
  73.  
  74.  
  75.  
  76.  
  77. #print(variableFile.read())
  78. #print(constraintFile.read())
  79. #print(procedureFile.read())
  80.  
  81. #testing hello yoon made this comment hahahahaha
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement