Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Salil Chandra, Escher Campanella Project #1

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ae805e3
test
Apr 16, 2019
395f9dd
Removed args
chands10 Apr 16, 2019
4f6da62
Changed spacing
chands10 Apr 16, 2019
534089b
Added buttons
chands10 Apr 16, 2019
1c62905
Added data structure to solve table
chands10 Apr 16, 2019
763460f
Implemented next, prev, finish
chands10 Apr 16, 2019
5583979
Fixed spacing
chands10 Apr 16, 2019
6fc6415
started writing code for the enter file name button
Apr 16, 2019
cc60400
button
Apr 16, 2019
971079f
fixed enter button
Apr 16, 2019
f0fc6ec
Added text box
chands10 Apr 16, 2019
5ba95c2
Fixed buttons
chands10 Apr 16, 2019
a9141b3
fixed button errors to make sure only one window can be opened at a time
Apr 16, 2019
b855237
fixed merge things
Apr 16, 2019
fd86773
Edited current
chands10 Apr 16, 2019
1184cb8
added more button saftey stuff
Apr 16, 2019
4b923b4
Show all steps
chands10 Apr 16, 2019
990106c
worked on disabling buttons prev step and next step when needed
Apr 16, 2019
ed4695b
Changed buttons
chands10 Apr 16, 2019
bd3f793
Fixed merge
chands10 Apr 16, 2019
be6e5b2
pressing enter now does the same thing as clicking the enter button o…
Apr 16, 2019
6fd3e1c
Cleaned up
chands10 Apr 16, 2019
99a95c2
Merge branch 'master' of https://github.com/chands10/STT-Solver
chands10 Apr 16, 2019
d272114
Deleted time
chands10 Apr 16, 2019
f005e79
Added bat file
chands10 Apr 17, 2019
97336d3
fixed bug with enter key not be disabled when it is supposed to
Apr 17, 2019
1ab2b2d
Merge branch 'master' of https://github.com/chands10/STT-Solver
Apr 17, 2019
d4445d4
made the only button avaliable to click in the beginning the enter fi…
Apr 17, 2019
a62dbd8
put in titles for the windows
Apr 17, 2019
8f421fc
started new button
chands10 Apr 25, 2019
d51cf98
added documentation
chands10 Apr 25, 2019
2b26d33
Updated open interface
chands10 Apr 25, 2019
85f54b5
Button disabling
chands10 Apr 25, 2019
67e9aee
Polished code
chands10 Apr 25, 2019
478b158
Changed thing
chands10 Apr 26, 2019
803bb45
implemented new
chands10 Apr 26, 2019
2966555
Focus set
chands10 Apr 26, 2019
33c89a6
fixed new
chands10 Apr 26, 2019
df1bdfd
finish
chands10 Apr 26, 2019
fb65920
finished2
chands10 Apr 27, 2019
fe0f6d4
Added pdf
chands10 Apr 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
## Authors
2014:
Johnathan Michaels
2019:
Salil Chandra
Escher Campanella

## About
To Run:
- Command Line: python3 project.py inputfile.txt
- IDLE: Run the program. Upon running, you will be prompted to enter the input file.
- Hit enter to get the next step
Double click on STT-Solver.bat. Click new and enter in statements (click enter on the keyboard twice when finished or press enter button). Can also click open and enter the input file. Click enter to start solving problem.

Format of input file:
- n lines
Expand Down
1 change: 1 addition & 0 deletions STT-Solver.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python project.py
Binary file added Writeup 2019.docx
Binary file not shown.
Binary file added Writeup 2019.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions inputs/wrongformat.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
not valid format
282 changes: 249 additions & 33 deletions project.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Jonathan Michaels
# 5/6/14

import sys
from tkinter import *
from tkinter import filedialog
import os

class Statement:
def __init__(self, first=''):
Expand Down Expand Up @@ -240,20 +242,23 @@ def getStatement(line, i):
s.second.operation = line[i]
s.second.first = Statement(line[i+1])
else:
print('Invalid input file.')
sys.exit()
#print('Invalid input file.')
#sys.exit()
raise Exception("Invalid input.")
i += 1
elif line[i] in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
if s.operation == '' and s.first == '':
s.first = Statement(line[i])
elif s.second == '':
s.second = Statement(line[i])
else:
print('Invalid input file.')
sys.exit()
#print('Invalid input file.')
#sys.exit()
raise Exception("Invalid input.")
else:
print('Invalid input file.')
sys.exit()
#print('Invalid input file.')
#sys.exit()
raise Exception("Invalid input.")

i += 1
if s.second == '':
Expand Down Expand Up @@ -296,24 +301,26 @@ def isComplete(statements):


def solveTable(statements):
result = []

global changedLiterals
changedLiterals = dict()

for statement in statements[:-1]:
statement.assignment = True
statements[-1].assignment = False

print('Original Statements:')
result.append('Original Statements:\n')
for statement in range(len(statements)):
print(str(statement + 1) + ': ' + str(statements[statement]))
result[0] += str(statement + 1) + ': ' + str(statements[statement]) + "\n"

count = 0
while True:
# look for contradiction
for statement in range(len(statements)):
if not statements[statement].isValid():
print('\nContradiction found in Statement ' + str(statement + 1) + '! Therefore, this is valid.')
return
result[-1] += '\nContradiction found in Statement ' + str(statement + 1) + '! Therefore, this is valid.\n'
return result

# see if any literal's truth value needs to be propogated to all statements
if len(changedLiterals) > 0:
Expand All @@ -334,31 +341,240 @@ def solveTable(statements):
# no assignment was forced. check if the statements are complete
else:
if isComplete(statements):
print('\nNo contradiction found! Therefore, this is invalid.')
result[-1] += '\nNo contradiction found! Therefore, this is invalid.\n'
else:
print('\nNo forced move')
return
result[-1] += '\nNo forced move\n'
return result

input()
#input()
count += 1
print('\nStep ' + str(count) + ' - ' + toPrint)
result.append('Step ' + str(count) + ' - ' + toPrint + "\n")
for statement in range(len(statements)):
print(str(statement + 1) + ': ' + str(statements[statement]))
result[-1] += str(statement + 1) + ': ' + str(statements[statement]) + "\n"


class GUI(object):
def __init__(self, parent):
self.parent = parent
self.parent.title("STT-Solver")
self.main_frame = Frame(self.parent)
self.main_frame.pack()
self.top_frame = Frame(self.main_frame)
self.top_frame.pack(side=TOP)

self.bottom_frame = Frame(self.main_frame)
self.bottom_frame.pack(side=BOTTOM)

self.scrollbar = Scrollbar(self.parent)
self.scrollbar.pack( side = RIGHT, fill = Y )

self.text = Text(self.parent, yscrollcommand = self.scrollbar.set, state = DISABLED)
self.text.pack()

self.scrollbar.config( command = self.text.yview )

self.button7 = Button(self.top_frame, text="New", command=self.createInput)
self.button7.pack(side=LEFT)
self.button1 = Button(self.top_frame, text="Open", command=self.enterFileName)
self.button1.pack(side=LEFT)
self.button2 = Button(self.top_frame, text="Prev Step", command=self.prevStep)
self.button2.pack(side=LEFT)
self.button3=Button(self.top_frame, text="Next Step", command=self.nextStep)
self.button3.pack(side=LEFT)
self.button4=Button(self.top_frame, text="Show All Steps", command=self.showAllSteps)
self.button4.pack(side=LEFT)
self.button6 = Button(self.top_frame, text = "Last Step", command = self.lastStep)
self.button6.pack(side = LEFT)

self.button2.config(state = DISABLED)
self.button3.config(state = DISABLED)
self.button4.config(state = DISABLED)
self.button6.config(state = DISABLED)

#self.e1 = ""
self.file_window = ""
self.button5 = ""
self.fileName_error = ""
self.fileName_entered = False
self.text2 = ""
self.scrollbar2 = ""

self.table = []
self.current = -1 #current represents the state just printed out

#click New
def createInput(self):
self.file_window = Toplevel(self.parent)
self.file_window.title("New")
self.file_window.protocol("WM_DELETE_WINDOW", self.callback_file_window)

self.button1.config(state = DISABLED)
self.button2.config(state = DISABLED)
self.button3.config(state = DISABLED)
self.button4.config(state = DISABLED)
self.button6.config(state = DISABLED)
self.button7.config(state = DISABLED)

self.scrollbar2 = Scrollbar(self.file_window)
self.scrollbar2.pack( side = RIGHT, fill = Y )

self.text2 = Text(self.file_window, yscrollcommand = self.scrollbar2.set)
self.text2.pack()

self.scrollbar2.config(command = self.text2.yview)

file_frame = Frame(self.file_window)
file_frame.pack(side = BOTTOM)
self.button5 = Button(file_frame, text="Enter")
self.file_window.bind('<Return><Return>', self.inputHelper) #press enter twice to return
self.button5.bind('<Button-1>', self.inputHelper)
self.button5.pack(side = RIGHT)
self.file_window.focus_force()
self.text2.focus_set()

#click enter in createInput, will call enter_file
def inputHelper(self, self2):
inputted = self.text2.get("1.0",END)
inputted = inputted.strip().split("\n")
for i in range(len(inputted)):
inputted[i] += "\n"

self.file_window.destroy()
self.enter_file(inputted)

#click open (file browser)
def enterFileName(self):
start = os.getcwd() + "\\inputs"
self.parent.filename = filedialog.askopenfilename(initialdir = start,title = "Select file",filetypes = ((".txt Files","*.txt"),("All files","*.*")))
try:
file = open(self.parent.filename)
f = file.readlines()
file.close()
self.enter_file(f)
except:
pass

"""
def enterFileNameAlt(self):
self.file_window = Toplevel(self.parent)
self.file_window.title("Enter file name")
self.file_window.protocol("WM_DELETE_WINDOW", self.callback_file_window)

self.button1.config(state = DISABLED)
self.button2.config(state = DISABLED)
self.button3.config(state = DISABLED)
self.button4.config(state = DISABLED)
self.button6.config(state = DISABLED)
self.button7.config(state = DISABLED)

l1 = Label(self.file_window, text="File Name")
l1.pack( side = LEFT)

self.e1 = Entry(self.file_window, bd =5)
self.e1.pack(side = LEFT)

file_frame = Frame(self.file_window)
file_frame.pack(side = BOTTOM)

self.button5 = Button(file_frame, text="Enter")
self.file_window.bind('<Return>', self.enter_file)
self.button5.bind('<Button-1>', self.enter_file)
self.button5.pack(side = RIGHT)
self.file_window.focus_force()
self.e1.focus_set()
"""

#parse inputs and create table
def enter_file(self, f):
self.button7.config(state = NORMAL)
try:
statements = parseInput(f)
self.table = solveTable(statements)
self.button1.config(state = NORMAL)
#self.button2.config(state = NORMAL)
self.button3.config(state = NORMAL)
self.button4.config(state = NORMAL)
self.button6.config(state = NORMAL)

self.current = -1
self.fileName_entered = True

self.nextStep()
except Exception as e:
self.text.config(state = NORMAL)
self.text.delete(1.0,END)
self.text.insert(END, str(e))
self.text.config(state = DISABLED)

self.button1.config(state = NORMAL)
self.button2.config(state = DISABLED)
self.button3.config(state = DISABLED)
self.button4.config(state = DISABLED)
self.button6.config(state = DISABLED)

"""
def callback_fileName_error(self):
self.button5.config(state = NORMAL)
self.e1.config(state = NORMAL)
self.file_window.bind('<Return>', self.enter_file)
self.button5.bind('<Button-1>', self.enter_file)
self.fileName_error.destroy()
"""

#click x on window
def callback_file_window(self):
self.button1.config(state = NORMAL)
self.button7.config(state = NORMAL)
if self.fileName_entered == True:
self.button3.config(state = NORMAL)
self.button4.config(state = NORMAL)
self.button6.config(state = NORMAL)
try:
self.fileName_error.destroy()
self.file_window.destroy()
except:
self.file_window.destroy()


def prevStep(self):
self.current -= 2
self.nextStep();
self.button3.config(state = NORMAL)
if self.current == 0:
self.button2.config(state = DISABLED)


def nextStep(self):
self.current += 1
self.text.config(state = NORMAL)
self.text.delete(1.0,END)
self.text.insert(END, self.table[self.current])
self.text.config(state = DISABLED)
self.button2.config(state = NORMAL)

if self.current == 0:
self.button2.config(state = DISABLED)
if self.current == len(self.table)-1:
self.button3.config(state = DISABLED)
else:
self.button3.config(state = NORMAL)

def lastStep(self):
self.current = len(self.table) - 2
self.nextStep();

def showAllSteps(self):
self.current = len(self.table) - 1
self.text.config(state = NORMAL)
self.text.delete(1.0,END)
for i in range(len(self.table)):
self.text.insert(END, self.table[i])
self.text.config(state = DISABLED)
self.button3.config(state = DISABLED)
self.button2.config(state = NORMAL)


if len(sys.argv) != 2:
# ask for input file if none is provided
if len(sys.argv) == 1:
sys.argv.append(input("Enter input file: "))
else:
print('Invalid command line arguments.')
sys.exit()

f = open(sys.argv[1]).readlines()
statements = parseInput(f)
solveTable(statements)





if __name__ == "__main__":
root = Tk()
gui = GUI(root)
root.mainloop()