deletion_sql="DROP TABLE IF EXISTS {};".format(block_label_table)
cursor.execute(deletion_sql)
cursor.execute("CREATE TABLE {} AS SELECT m.block, MAX(tl.weight) as label from {} as m, {} as s, {} as tl where m.superblock = s.superblock and s.tuple = tl.tuple GROUP BY m.block; ".format(block_label_table,missing_data_table,superblock_table,tuple_label_table))
cursor.execute("CREATE UNIQUE INDEX ON {} (block)".format(block_label_table))
definitialize_equigraph():
deletion_sql="DROP TABLE IF EXISTS {};".format(equigraph_table)
definitialize_graph():
deletion_sql="DROP TABLE IF EXISTS {};".format(graph_table)
cursor.execute("INSERT INTO {}(block, tuple, max_occurence) SELECT m.block, s.tuple, 0 AS max_occurence FROM {} as m, {} as s where m.superblock = s.superblock".format(equigraph_table,missing_data_table,superblock_table))
cursor.execute("UPDATE {} SET max_occurence = 1 WHERE (tuple, block) IN (SELECT tl.tuple, bl.block FROM {} AS tl, {} AS bl WHERE tl.weight = bl.label);".format(equigraph_table,tuple_label_table,block_label_table))
definitialize_matching():
deletion_sql="DROP TABLE IF EXISTS {};".format(matching_table)
cursor.execute("INSERT INTO {}(block, tuple, occurence, eq) SELECT m.block, s.tuple, 1 AS occurence, false AS eq FROM {} as m, {} as s where m.superblock = s.superblock".format(graph_table,missing_data_table,superblock_table))
cursor.execute("UPDATE {} SET eq = true WHERE (tuple, block) IN (SELECT tl.tuple, bl.block FROM {} AS tl, {} AS bl WHERE tl.weight = bl.label);".format(graph_table,tuple_label_table,block_label_table))
cursor.execute("CREATE INDEX ON {} (block)".format(graph_table))
cursor.execute("CREATE INDEX ON {} (tuple,occurence)".format(graph_table))
cursor.execute("CREATE INDEX ON {} (eq)".format(graph_table))
cursor.execute("CREATE INDEX ON {} (matching)".format(graph_table))
# def initialize_matching():
# deletion_sql = "DROP TABLE IF EXISTS {};".format(matching_table)
AND tl.occurence = 1 AND tb.block = e.block""".format(equigraph_table,tuple_label_table,block_label_table,tuple_label_table,equigraph_table,tuple_label_table,block_label_table),[tuple(S),db_size,tuple(S)])
SELECT g.block, g.tuple, g.occurence, tl.weight, bl.label, tl.label, true AS existing
FROM {} AS g, {} AS bl, {} AS tl
WHERE tl.tuple = g.tuple AND tl.occurence = g.occurence AND bl.block = g.block
# skip the edge not considered so far whose tuple is in T
continue
a=row[4]+row[5]-row[3]
ifa<alpha:
...
...
@@ -263,31 +308,59 @@ def update_labels(S, T):
edges_to_add=[]
ifa==alpha:
edges_to_add.append(row)
mt=time.monotonic()
globallookup_time
lookup_time+=mt-start
mt2=mt
cursor.execute("UPDATE {} SET label = label - %s WHERE block in %s".format(block_label_table),[alpha,tuple(S)])
iflen(T)>0:
cursor.execute("UPDATE {} SET label = label + %s WHERE (tuple, occurence) in %s".format(tuple_label_table),[alpha,tuple(T)])
cursor.execute("UPDATE {} SET max_occurence = CASE WHEN max_occurence > 0 THEN max_occurence -1 ELSE 0 END WHERE (tuple, max_occurence) in %s AND block NOT IN %s".format(equigraph_table),[tuple(T),tuple(S)])
# remove from the equigraph the edges from T and a block not in S
mt2=time.monotonic()
globalupdate_time1
update_time1+=mt2-mt
cursor.execute("DELETE FROM {} WHERE eq = True AND occurence > 1 AND (tuple, occurence) in %s AND block NOT IN %s".format(graph_table),[tuple(T),tuple(S)])
cursor.execute("UPDATE {} SET eq = False WHERE occurence = 1 AND (tuple, occurence) in %s AND block NOT IN %s".format(graph_table),[tuple(T),tuple(S)])
mt3=time.monotonic()
globalupdate_time2
update_time2+=mt3-mt2
globaledges_nb
edges_nb+=len(edges_to_add)
globalmax_S
max_S=max(len(S),max_S)
foredgeinedges_to_add:
cursor.execute("INSERT INTO {} (tuple, occurence, label, weight) VALUES (%s, %s, %s, %s) ON CONFLICT DO NOTHING".format(tuple_label_table),[edge[1],edge[2],edge[5],edge[3]])
cursor.execute("UPDATE {} SET max_occurence = %s WHERE block = %s AND tuple = %s".format(equigraph_table),[edge[2],edge[0],edge[1]])
# input("updated labels with S={}, T={} and alpha={} \n with edges {}".format(S,T, alpha, edges_to_add))
# if the edge exists in the graph already
ifedge[6]:
cursor.execute("UPDATE {} SET eq = true WHERE block = %s AND tuple = %s AND occurence = %s".format(graph_table),[edge[0],edge[1],edge[2]])
else:
cursor.execute("INSERT INTO {} (tuple, occurence, label, weight) VALUES (%s, %s, %s, %s) ON CONFLICT DO NOTHING".format(tuple_label_table),[edge[1],edge[2],edge[5],edge[3]])