Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AICogSciFinalProject
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mrk022
AICogSciFinalProject
Commits
8ecfff01
Commit
8ecfff01
authored
Dec 02, 2019
by
mrk022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated tree.py to handle variable nodes
parent
1e7de1fe
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
9 deletions
+34
-9
queue.py
queue.py
+2
-2
queue.pyc
queue.pyc
+0
-0
tree.py
tree.py
+32
-6
tutor.py
tutor.py
+0
-1
No files found.
queue.py
View file @
8ecfff01
...
...
@@ -20,8 +20,8 @@ class Queue:
# When queue is half full, compress it. This
# achieves an amortized complexity of O(1) while
# not letting the list continue to grow unchecked.
if
self
.
frontIdx
*
2
>
len
(
self
.
items
):
self
.
__compress
()
#
if self.frontIdx * 2 > len(self.items):
#
self.__compress()
item
=
self
.
items
[
self
.
frontIdx
]
self
.
frontIdx
+=
1
...
...
queue.pyc
View file @
8ecfff01
No preview for this file type
tree.py
View file @
8ecfff01
# base tree code from http://knuth.luther.edu/~leekent/CS2Plus/chap6/chap6.html
# changed this code to allow for variable functions, and change infix expressions to postfix
# added variable node class to consider when both nodes have variables in them
import
queue
...
...
@@ -9,6 +10,16 @@ class TimesNode:
self
.
right
=
right
def
eval
(
self
):
'''if check_if_variables(str(self.left.eval()), str(self.right.eval())) == "both_vars":
v1 = str(self.left.eval()).split("x")[0]
v2 = str(self.right.eval()).split("x")[0]
evalStr = v1 + "*" + v2
return eval(evalStr)
else:
return self.left.eval() * self.right.eval()'''
#if isinstance(self.left, VariableNode):
# return self.left.getMultiplier() * self.left.getMultiplier()
#else:
return
self
.
left
.
eval
()
*
self
.
right
.
eval
()
def
inorder
(
self
):
...
...
@@ -47,6 +58,17 @@ class NumNode:
def
inorder
(
self
):
return
str
(
self
.
num
)
class
VariableNode
:
def
__init__
(
self
,
value
):
self
.
value
=
value
def
eval
(
self
):
# get value before x
return
float
(
self
.
value
.
split
(
"x"
)[
0
])
def
inorder
(
self
):
return
str
(
self
.
eval
())
def
check_if_variables
(
x
,
y
):
if
'x'
in
x
and
'x'
in
y
:
return
"both_vars"
...
...
@@ -60,7 +82,6 @@ def E(q):
raise
ValueError
(
"Invalid Prefix Expression"
)
token
=
q
.
dequeue
()
if
token
==
"+"
:
return
PlusNode
(
E
(
q
),
E
(
q
))
...
...
@@ -70,11 +91,15 @@ def E(q):
if
token
==
"-"
:
return
MinusNode
(
E
(
q
),
E
(
q
))
try
:
#try:
if
"x"
in
token
:
output
=
VariableNode
(
token
)
# make a different class for variable node
else
:
output
=
NumNode
(
float
(
token
))
except
:
print
(
"Not a valid operation, need variables of like terms"
)
output
=
NumNode
(
float
(
0
))
#
except:
#
print("Not a valid operation, need variables of like terms")
#
output = NumNode(float(0))
return
output
OPERATORS
=
set
([
'+'
,
'-'
,
'*'
,
'/'
,
'('
,
')'
])
...
...
@@ -144,7 +169,8 @@ def split_equation(equation):
return
expressions
def
main
():
exp
=
split_equation
(
"3 * 4 - 6=0"
)
exp
=
split_equation
(
"4x * 3x"
)
eval_tree
(
exp
[
0
])
...
...
tutor.py
View file @
8ecfff01
...
...
@@ -101,7 +101,6 @@ class IntelligentTutor(ACTR):
goal
=
Buffer
()
user
=
UserState
(
"4x+7=5x+2"
)
def
init
():
user
.
get_input
()
goal
.
set
(
user
.
state
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment