/** * Создать новый дерево МДНФ * * \param [in] eachChild простые импликанты * \param [in] mincf число, биты которого описывается МДНФ * \param [in] fullExp полный вид функции */ public function make_min_tree($eachChild, $mincf, $fullExp) { // удалить текущие сыновья $this->childrens = array(); for ($i = 0; $i < count($eachChild); $i++) { // Если i-й бит включенно if ($mincf >> $i & 1 == 1) { $isOne = -1 == $this->find_first_not_of($eachChild[$i], '-', $this->find_first_not_of($eachChild[$i], '-') + 1); if ($isOne) { // только 1 операнд $pos = $this->find_first_not_of($eachChild[$i], '-'); if ($pos != -1) { if ($eachChild[$i][$pos] == '1') { array_push($this->childrens, clone $fullExp[$pos]); } else { $tmp = new qtype_correctwriting_not_logic_operator(); $tmp->children = clone $fullExp[$pos]; array_push($this->childrens, $tmp); $tmp->calculate_tree_in_string(); } } } else { // операция && $tmp = new qtype_correctwriting_and_logic_operator(); for ($j = 0; $j < strlen($eachChild[$i]); $j++) { if ($eachChild[$i][$j] == '1') { array_push($tmp->childrens, clone $fullExp[$j]); } elseif ($eachChild[$i][$j] == '0') { $notOp = new qtype_correctwriting_not_logic_operator(); $notOp->children = clone $fullExp[$j]; $notOp->calculate_tree_in_string(); array_push($tmp->childrens, $notOp); } } $tmp->sort_childrens(); $tmp->calculate_tree_in_string(); array_push($this->childrens, $tmp); } } } }
public function convert($parent) { $this->convert_each_childrens(); // сортировать правый и левый if ($this->left->treeinstring > $this->right->treeinstring) { $tmp = $this->left; $this->left = $this->right; $this->right = $tmp; } // преобразовать в вид не равно $tmp = new qtype_correctwriting_not_logic_operator(); $t = new qtype_correctwriting_equal_operator(); $t->right = $this->right; $t->left = $this->left; $t->calculate_tree_in_string(); $tmp->children = $t; $tmp->calculate_tree_in_string(); $this->ptonewchild = $tmp; }