Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-07-20 15:27:46 +0200
committerErich Eckner <git@eckner.net>2018-07-25 14:21:25 +0200
commit1a07793e9947836d8f8a26c605c0dcfc4955b615 (patch)
tree213420cd784610346420809a3abeb447e9c44f05
parent7e2276029aebdea3ca4836f46268fcce98812058 (diff)
bugfixes in `find_the_culprit`
-rwxr-xr-xbin/bootstrap-mysql126
-rwxr-xr-xbin/why-dont-you4
2 files changed, 88 insertions, 42 deletions
diff --git a/bin/bootstrap-mysql b/bin/bootstrap-mysql
index 351971b..339a973 100755
--- a/bin/bootstrap-mysql
+++ b/bin/bootstrap-mysql
@@ -370,7 +370,7 @@ fi
printf 'DROP PROCEDURE IF EXISTS `find_the_culprit`//\n'
printf 'CREATE PROCEDURE `find_the_culprit`(IN `knot_id` BIGINT)\n'
printf 'find_the_culprit:BEGIN\n'
- printf 'DECLARE max_relevance_level INT DEFAULT 0;\n'
+ printf 'DECLARE max_trial_iteration INT DEFAULT 0;\n'
printf 'DECLARE min_edges_count INT DEFAULT 0;\n'
printf 'CREATE TEMPORARY TABLE `todo_knots` ('
@@ -382,7 +382,7 @@ fi
printf 'UPDATE `knots`'
printf ' SET `knots`.`reason_length`=NULL,'
- printf ' `knots`.`relevance_level`=NULL,'
+ printf ' `knots`.`trial_iteration`=NULL,'
printf ' `knots`.`active`=1;\n'
printf 'DELETE FROM `edges_copy`;\n'
printf 'INSERT INTO `edges_copy` (`cause`,`impact`,`invert`)'
@@ -393,45 +393,93 @@ fi
printf 'UPDATE `knots`'
printf ' SET `knots`.`reason_length`=0,'
+ printf '`knots`.`trial_iteration`=0,'
printf '`knots`.`active`=1'
printf ' WHERE `knots`.`id`=`knot_id`;\n'
printf 'trial_loop: REPEAT\n'
+ printf 'UPDATE `knots_copy`'
+ printf ' JOIN `knots`'
+ printf ' ON `knots_copy`.`id`=`knots`.`id`'
+ printf ' SET `knots_copy`.`reason_length`=`knots`.`reason_length`,'
+ printf '`knots_copy`.`active`=`knots`.`active`,'
+ printf '`knots_copy`.`trial_iteration`=`knots`.`trial_iteration`;\n'
-# about which relevane_level should we care?
-
- # test here for contradictions: "exists" & "foreach" conditions
- printf 'SELECT max_relevance_level:=MIN(`i_k`.`relevance_level`)'
- printf ' FROM `knots` AS `i_k`'
- printf ' JOIN `edges`'
- printf ' ON `edges`.`impact`=`i_k`.`id`'
- printf ' JOIN `knots_copy` AS `c_k`'
- printf ' ON `edges`.`cause`=`c_k`.`id`'
- printf ' WHERE `i_k`.`reason_length` IS NOT NULL'
- printf ' AND `i_k`.'
-
-
- printf ''
+ # the trial_iteration we should care about
+ printf 'SET max_trial_iteration = ('
+ printf 'SELECT MAX(`knots`.`trial_iteration`)'
+ printf ' FROM `knots`'
+ printf ' WHERE `knots`.`reason_length` IS NOT NULL'
+ printf ');\n'
- # start again if something was done
- printf 'IF (ROW_COUNT() != 0)'
- printf ' ITERATE `trial_loop`\n'
+printf 'SELECT max_trial_iteration;\n'
+
+ # test for contradictions
+ action_on_contradiction=$(
+ # the cause of current trial_iteration
+ printf 'UPDATE `knots` AS `i_k`'
+ printf ' JOIN `edges`'
+ printf ' ON `edges`.`impact`=`i_k`.`id`'
+ printf ' JOIN `knots_copy` AS `c_k`'
+ printf ' ON `edges`.`cause`=`c_k`.`id`'
+ printf ' SET `c_k`.`trial_iteration`=`i_k`.`trial_iteration`'
+ printf ' WHERE `i_k`.`reason_length` IS NOT NULL'
+ printf ' AND `c_k`.`reason_length` IS NOT NULL'
+ printf ' AND `i_k`.`relevanve_level`<max_trial_iteration'
+ printf ' AND `c_k`.`relevanve_level`=max_trial_iteration;\n'
+ # reset all other knots of current trial_iteration
+ printf 'UPDATE `knots`'
+ printf ' SET `knots`.`reason_length`=NULL'
+ printf ' WHERE `knots`.`trial_iteration`=max_trial_iteration;\n'
+ # restart loop
+ printf 'ITERATE `trial_loop`;\n'
+ )
+ printf 'IF ('
+ printf 'EXISTS ('
+ printf 'SELECT 1'
+ printf ' FROM `knots` AS `i_k`'
+ printf ' JOIN `edges`'
+ printf ' ON `edges`.`impact`=`i_k`.`id`'
+ printf ' JOIN `knots_copy` AS `c_k`'
+ printf ' ON `edges`.`cause`=`c_k`.`id`'
+ printf ' WHERE `i_k`.`reason_length` IS NOT NULL'
+ printf ' AND `c_k`.`reason_length` IS NOT NULL'
+ # "foreach" condition
+ printf ' AND (`i_k`.`and`=`i_k`.`active`)'
+ printf ' AND (`c_k`.`active` XOR `edges`.`invert` XOR `i_k`.`active`)'
+ printf ')'
+ printf ') THEN\n'
+ printf '%s\n' "${action_on_contradiction}"
+ printf 'END IF;\n'
+ printf 'IF ('
+ printf 'EXISTS ('
+ printf 'SELECT 1'
+ printf ' FROM `knots` AS `i_k`'
+ printf ' WHERE `i_k`.`reason_length` IS NOT NULL'
+ # "exists" condition
+ printf ' AND (`i_k`.`and` XOR `i_k`.`active`)'
+ printf ' AND NOT EXISTS ('
+ printf 'SELECT 1'
+ printf ' FROM `edges`'
+ printf ' JOIN `knots_copy` AS `c_k`'
+ printf ' ON `edges`.`cause`=`c_k`.`id`'
+ printf ' WHERE `edges`.`impact`=`i_k`.`id`'
+ printf ' AND ('
+ printf '(`c_k`.`active` XOR `edges`.`invert` = `i_k`.`active`)'
+ printf ' OR `c_k`.`reason_length` IS NULL'
+ printf ')'
+ printf ')'
+ printf ')'
+ printf ') THEN\n'
+ printf '%s\n' "${action_on_contradiction}"
printf 'END IF;\n'
+printf 'select "TEST";\n'
# if the proof is done, all the steps below will find nothing which
# is still to be proven, and the loop will end
- printf 'UPDATE `knots_copy`'
- printf ' JOIN `knots`'
- printf ' ON `knots_copy`.`id`=`knots`.`id`'
- printf ' SET `knots_copy`.`reason_length`=`knots`.`reason_length`,'
- printf '`knots_copy`.`active`=`knots`.`active`,'
- printf '`knots_copy`.`relevance_level`=`knots`.`relevance_level`;\n'
-
# set cause-knots of and = 1 / or = 0 (which is unambiguous => fast)
- printf 'SET row_count_saved = 0;\n'
-
printf 'UPDATE `knots` AS `c_k`'
printf ' JOIN `edges`'
printf ' ON `edges`.`cause`=`c_k`.`id`'
@@ -439,20 +487,16 @@ fi
printf ' ON `edges`.`impact`=`i_k`.`id`'
printf ' SET `c_k`.`active`=(`i_k`.`active` XOR `edges`.`invert`),'
printf '`c_k`.`reason_length`=`i_k`.`reason_length`+1,'
- printf '`c_k`.`relevance_level`=`i_k`.`relevance_level`'
+ printf '`c_k`.`trial_iteration`=`i_k`.`trial_iteration`'
printf ' WHERE `c_k`.`reason_length` IS NULL'
printf ' AND `i_k`.`reason_length` IS NOT NULL'
printf ' AND (`i_k`.`and`=`i_k`.`active`);\n'
# start again if something was done
- printf 'IF (ROW_COUNT() != 0)'
- printf ' ITERATE `trial_loop`\n'
+ printf 'IF (ROW_COUNT() != 0) THEN\n'
+ printf 'ITERATE `trial_loop`;\n'
printf 'END IF;\n'
- printf 'SELECT max_relevance_level:=IFNULL(MAX(`knots`.`relevance_level`),0)'
- printf ' FROM `knots`'
- printf ' WHERE `knots`.`reason_length` IS NOT NULL;\n'
-
# try through ambiguous knots:
# and = 0 with all reasoned causes = 1
# or = 1 with all reasoned causes = 0
@@ -478,7 +522,7 @@ fi
printf 'IF('
# is this knot already proven?
printf '`c_k`.`reason_length` IS NOT NULL'
- printf ' AND (`c_k`.`active` XOR `edges`.`invert` = `i_k`.`active`)'
+ printf ' AND (`c_k`.`active` XOR `edges`.`invert` = `i_k`.`active`),'
printf '1,'
printf '0'
printf ')'
@@ -494,9 +538,11 @@ fi
printf ' AND (`i_k`.`and` XOR `i_k`.`active`)'
printf ' GROUP BY `i_k`.`id`;\n'
- printf 'SELECT min_edges_count:=MIN(`todo_knots`.`edges_count`)'
- printf ' FROM `todo_knots`'
- printf ' WHERE NOT `todo_knots`.`irrelevant`;\n'
+ printf 'SET min_edges_count = ('
+ printf 'SELECT MIN(`todo_knots`.`edges_count`)'
+ printf ' FROM `todo_knots`'
+ printf ' WHERE NOT `todo_knots`.`irrelevant`'
+ printf ');\n'
printf 'DELETE FROM `todo_knots`'
printf ' WHERE `todo_knots`.`irrelevant`'
@@ -511,7 +557,7 @@ fi
printf ' ON `edges`.`impact`=`i_k`.`id`'
printf ' SET `c_k`.`active`=(`i_k`.`active` XOR `edges`.`invert`),'
printf '`c_k`.`reason_length`=`i_k`.`reason_length`+1,'
- printf '`c_k`.`relevance_level`=max_relevance_level+1+`c_k`.`id`'
+ printf '`c_k`.`trial_iteration`=max_trial_iteration+1+`c_k`.`id`'
printf ';\n'
# start again if something was done
diff --git a/bin/why-dont-you b/bin/why-dont-you
index 78587a5..dc57e87 100755
--- a/bin/why-dont-you
+++ b/bin/why-dont-you
@@ -251,9 +251,9 @@ case "${action}" in
printf ' `and` BIT,'
printf ' `content_id` BIGINT,'
printf ' `content_type` ENUM("bpir","it"),'
- printf ' `reason_length` MEDIUMINT,'
+ printf ' `trial_iteration` MEDIUMINT,'
printf ' `active` BIT,'
- printf ' `relevance_level` MEDIUMINT,'
+ printf ' `reason_length` MEDIUMINT,'
printf ' UNIQUE KEY (`id`),'
printf ' UNIQUE KEY `content`(`content_id`,`content_type`));\n'
printf 'CREATE TEMPORARY TABLE `edges%s` (' \