Beispiel #1
0
    // Propagate the last node in _nodes_to_propagate. This means applying all the constraints in its clusters. Returns false if we get a conflict from this propagation
    private bool Propagate()
    {
        int node_idx_to_propagate = UTL.ExtractBack(ref _nodes_to_propagate);

        if (_nodes[node_idx_to_propagate].is_propagated)
        {
            return(true);                                              // the node has already been propagated. Shouldn't happen
        }
        bool legal_propagation = true;

        if (_nodes[node_idx_to_propagate].is_true)
        {
            foreach (int neighbour_idx in _nodes[node_idx_to_propagate].neighbour_ids)
            {
                if (!GiveValueToNode(neighbour_idx, false))
                {
                    legal_propagation = false;
                }
            }
        }
        foreach (int cluster_idx in _nodes[node_idx_to_propagate].cluster_ids)
        {
            if (!GiveNodeValueToCluster(ref _clusters[cluster_idx], _nodes[node_idx_to_propagate].is_true))
            {
                legal_propagation = false;
            }
        }
        _nodes[node_idx_to_propagate].is_propagated = true;
        ++_num_fixed_nodes_propagated;
        return(legal_propagation);
    }
Beispiel #2
0
    // removes the last Guess, since it proved to be wrong
    private void RemoveLastGuess()
    {
        if (_guess_list.Count == 0)
        {
            return;                          // this should never happen
        }
        for (int node_idx = 0; node_idx < Volume; ++node_idx)
        {
            if (_nodes[node_idx].time == NumGuesses())
            {
                FreeNode(node_idx);
            }
            ;
        }
        int last_guessed_node = UTL.ExtractBack(ref _guess_list);

        GiveValueToNode(last_guessed_node, false);
        _nodes_to_propagate = new List <int> {
            last_guessed_node
        };
    }