enhance bb tree algorithm
This commit is contained in:
parent
613dfa49bd
commit
4ecad56d3b
|
@ -19,6 +19,15 @@ CELL_HEIGHT = 5
|
||||||
GRAPH_CONTENTOFFSET_X = 40
|
GRAPH_CONTENTOFFSET_X = 40
|
||||||
GRAPH_CONTENTOFFSET_Y = 40
|
GRAPH_CONTENTOFFSET_Y = 40
|
||||||
|
|
||||||
|
class dbPLinkInputOutputType(object):
|
||||||
|
PIN = 0
|
||||||
|
POUT = 1
|
||||||
|
PLOCAL = 2
|
||||||
|
PTARGET = 3
|
||||||
|
|
||||||
|
class dbBLinkInputOutputType(object):
|
||||||
|
INPUT = 0
|
||||||
|
OUTPUT = 1
|
||||||
|
|
||||||
class LinkType(object):
|
class LinkType(object):
|
||||||
PLOCAL = 0
|
PLOCAL = 0
|
||||||
|
@ -37,9 +46,13 @@ class BBResult(object):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.assistName = assistName
|
self.assistName = assistName
|
||||||
self.pin = int(pin)
|
self.pin = int(pin)
|
||||||
|
self.pinData = []
|
||||||
self.pout = int(pout)
|
self.pout = int(pout)
|
||||||
|
self.poutData = []
|
||||||
self.bin = int(bin)
|
self.bin = int(bin)
|
||||||
|
self.binData = []
|
||||||
self.bout = int(bout)
|
self.bout = int(bout)
|
||||||
|
self.boutData = []
|
||||||
self.x = 0.0
|
self.x = 0.0
|
||||||
self.y = 0.0
|
self.y = 0.0
|
||||||
self.width = 0.0
|
self.width = 0.0
|
||||||
|
|
|
@ -19,7 +19,7 @@ def run():
|
||||||
|
|
||||||
# decorate each graph
|
# decorate each graph
|
||||||
for i in graphList:
|
for i in graphList:
|
||||||
(plocal_layer, bbMap, operMap) = buildBB(exportCur, decorateCur, i)
|
(plocal_layer, bbMap, operMap) = buildBlock(exportCur, decorateCur, i)
|
||||||
|
|
||||||
# give up all change of eexport.db (because no change)
|
# give up all change of eexport.db (because no change)
|
||||||
exportDb.close()
|
exportDb.close()
|
||||||
|
@ -30,7 +30,7 @@ def initDecorateDb(cur):
|
||||||
cur.execute("CREATE TABLE graph([graph] INTEGER, [graph_name] TEXT, [width] INTEGER, [height] INTEGER, [index] INTEGER, [belong_to] TEXT);")
|
cur.execute("CREATE TABLE graph([graph] INTEGER, [graph_name] TEXT, [width] INTEGER, [height] INTEGER, [index] INTEGER, [belong_to] TEXT);")
|
||||||
cur.execute("CREATE TABLE info([target] INTEGER, [field] TEXT, [data] TEXT);")
|
cur.execute("CREATE TABLE info([target] INTEGER, [field] TEXT, [data] TEXT);")
|
||||||
|
|
||||||
cur.execute("CREATE TABLE block([belong_to_graph] INETGER, [thisobj] INTEGER, [name] TEXT, [assist_text] TEXT, [pin-pin] INTEGER, [pin-pout] INTEGER, [pin-bin] INTEGER, [pin-bout] INTEGER, [x] REAL, [y] REAL, [width] REAL, [height] REAL, [expandable] INTEGER);")
|
cur.execute("CREATE TABLE block([belong_to_graph] INETGER, [thisobj] INTEGER, [name] TEXT, [assist_text] TEXT, [pin-pin] TEXT, [pin-pout] TEXT, [pin-bin] TEXT, [pin-bout] TEXT, [x] REAL, [y] REAL, [width] REAL, [height] REAL, [expandable] INTEGER);")
|
||||||
cur.execute("CREATE TABLE cell([belong_to_graph] INETGER, [thisobj] INTEGER, [name] TEXT, [assist_text] TEXT, [x] REAL, [y] REAL, [type] INTEGER);")
|
cur.execute("CREATE TABLE cell([belong_to_graph] INETGER, [thisobj] INTEGER, [name] TEXT, [assist_text] TEXT, [x] REAL, [y] REAL, [type] INTEGER);")
|
||||||
cur.execute("CREATE TABLE link([belong_to_graph] INETGER, [thisobj] INTEGER, [delay] INTEGER, [startobj] INTEGER, [endobj] INTEGER, [start_index] INTEGER, [end_index] INTEGER, [x1] REAL, [y1] REAL, [x2] REAL, [y2] REAL);")
|
cur.execute("CREATE TABLE link([belong_to_graph] INETGER, [thisobj] INTEGER, [delay] INTEGER, [startobj] INTEGER, [endobj] INTEGER, [start_index] INTEGER, [end_index] INTEGER, [x1] REAL, [y1] REAL, [x2] REAL, [y2] REAL);")
|
||||||
|
|
||||||
|
@ -62,13 +62,13 @@ def decorateGraph(exCur, deCur, graph):
|
||||||
# sub bb
|
# sub bb
|
||||||
deCur.execute("INSERT INTO graph VALUES(?, ?, 0, 0, -1, '')", (lines[0], lines[2]))
|
deCur.execute("INSERT INTO graph VALUES(?, ?, 0, 0, -1, '')", (lines[0], lines[2]))
|
||||||
|
|
||||||
def buildBB(exCur, deCur, target):
|
def buildBlock(exCur, deCur, target):
|
||||||
# sort inner bb
|
# sort inner bb
|
||||||
# use current graph input as the start point
|
# use current graph input as the start point
|
||||||
treeRoot = dcv.BBTreeNode(target, -1)
|
treeRoot = dcv.BBTreeNode(target, -1)
|
||||||
processedBB = set()
|
processedBB = set()
|
||||||
# layer start from 2, 0 is occupied for pLocal, 1 is occupied for pOper
|
# layer start from 2, 0 is occupied for pLocal, 1 is occupied for pOper
|
||||||
arrangedLayer = recursiveBuildBBTree(treeRoot, exCur, deCur, processedBB, 2, 0, target)
|
arrangedLayer = recursiveBuildBBTree(treeRoot, exCur, processedBB, 2, 0, target)
|
||||||
|
|
||||||
# get no linked bb and place them. linked bb position will be computed following
|
# get no linked bb and place them. linked bb position will be computed following
|
||||||
# calc each bb's x postion, as for y, calc later
|
# calc each bb's x postion, as for y, calc later
|
||||||
|
@ -128,48 +128,27 @@ def buildBB(exCur, deCur, target):
|
||||||
# write to database and return
|
# write to database and return
|
||||||
for i in bbResult.keys():
|
for i in bbResult.keys():
|
||||||
cache = bbResult[i]
|
cache = bbResult[i]
|
||||||
deCur.execute('INSERT INTO block VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', (target, i, cache.name, cache.assistName, cache.pin, cache.pout, cache.bin, cache.bout, cache.x, cache.y, cache.width, cache.height, cache.expandable))
|
deCur.execute('INSERT INTO block VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||||
|
(target, i, cache.name, cache.assistName, cache.pin, cache.pout, cache.bin, cache.bout, cache.x, cache.y, cache.width, cache.height, cache.expandable))
|
||||||
for i in operResult.keys():
|
for i in operResult.keys():
|
||||||
cache = operResult[i]
|
cache = operResult[i]
|
||||||
deCur.execute("INSERT INTO block VALUES (?, ?, ?, '', 2, 1, 0, 0, ?, ?, ?, ?, -1)", (target, i, cache.name, cache.x, cache.y, cache.width, cache.height))
|
deCur.execute("INSERT INTO block VALUES (?, ?, ?, '', 2, 1, 0, 0, ?, ?, ?, ?, -1)",
|
||||||
|
(target, i, cache.name, cache.x, cache.y, cache.width, cache.height))
|
||||||
|
|
||||||
return (layer_y[0] - dcv.CELL_HEIGHT, bbResult, operResult)
|
return (layer_y[0] - dcv.CELL_HEIGHT, bbResult, operResult)
|
||||||
|
|
||||||
def recursiveBuildBBTree(node, exCur, deCur, processedBB, layer, depth, graphId):
|
def recursiveBuildBBTree(node, exCur, processedBB, layer, depth, graphId):
|
||||||
cache = []
|
realLinkedBB = set()
|
||||||
if depth == 0:
|
|
||||||
# find bIn
|
|
||||||
exCur.execute('SELECT [thisobj] FROM bIn WHERE [belong_to] == ?;', (node.bb,))
|
|
||||||
else:
|
|
||||||
# find bOut
|
|
||||||
exCur.execute('SELECT [thisobj] FROM bOut WHERE [belong_to] == ?;', (node.bb,))
|
|
||||||
|
|
||||||
for i in exCur.fetchall():
|
|
||||||
cache.append(i[0])
|
|
||||||
|
|
||||||
if (len(cache) == 0):
|
|
||||||
return layer
|
|
||||||
|
|
||||||
# find links
|
# find links
|
||||||
exCur.execute("SELECT [output] FROM bLink WHERE ([belong_to] == ? AND ([input] IN ({})));".format(','.join(map(lambda x:str(x), cache))), (graphId,))
|
exCur.execute("SELECT [output_obj] FROM bLink WHERE ([input_obj] == ? AND [input_type] == ? AND [belong_to] = ?) ORDER BY [input_index] ASC;",
|
||||||
cache.clear()
|
(node.bb, (dcv.dbBLinkInputOutputType.INPUT if depth == 0 else dcv.dbBLinkInputOutputType.OUTPUT), graphId))
|
||||||
for i in exCur.fetchall():
|
for i in exCur.fetchall():
|
||||||
cache.append(i[0])
|
realLinkedBB.add(i[0])
|
||||||
|
|
||||||
if (len(cache) == 0):
|
|
||||||
return layer
|
|
||||||
|
|
||||||
#find bIn (find in bIn list to omit the line linked to current bb's output)
|
|
||||||
exCur.execute("SELECT [belong_to] FROM bIn WHERE [thisobj] IN ({});".format(','.join(map(lambda x:str(x), cache))))
|
|
||||||
cache.clear()
|
|
||||||
for i in exCur.fetchall():
|
|
||||||
cache.append(i[0])
|
|
||||||
|
|
||||||
if (len(cache) == 0):
|
if (len(cache) == 0):
|
||||||
return layer
|
return layer
|
||||||
|
|
||||||
# ignore duplicated bb
|
# ignore duplicated bb
|
||||||
realLinkedBB = set(cache)
|
|
||||||
# calc need processed bb first
|
# calc need processed bb first
|
||||||
# and register all gotten bb. for preventing infinity resursive func and keep bb tree structure
|
# and register all gotten bb. for preventing infinity resursive func and keep bb tree structure
|
||||||
realLinkedBB = realLinkedBB - processedBB
|
realLinkedBB = realLinkedBB - processedBB
|
||||||
|
|
|
@ -4,7 +4,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# debug use
|
# debug use
|
||||||
# os.remove('decorate.db')
|
os.remove('decorate.db')
|
||||||
|
|
||||||
print('Super Script View')
|
print('Super Script View')
|
||||||
if not os.path.isfile("decorate.db"):
|
if not os.path.isfile("decorate.db"):
|
||||||
|
@ -18,4 +18,4 @@ if not os.path.isfile("decorate.db"):
|
||||||
print('Decorated database generating done.')
|
print('Decorated database generating done.')
|
||||||
|
|
||||||
# todo: start flask
|
# todo: start flask
|
||||||
ServerCore.run()
|
# ServerCore.run()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user