// Copy constructor that copies the contents of the
// parameterized list of states into this neighborhood.
Neighborhood::Neighborhood(const vector<State> &s)
{
    for (unsigned i = 0; i < s.size(); ++i)
        addNbr(Relationship(), s[i]);
}
Beispiel #2
0
//------------------------------------------------------------------------------
// Add cluster to a tree
int NTree::AddCluster (IntegerSet &b, char *label)
{
	Error = 0;
	int n = b.size();
	if (n > 1 && n < ((NNodePtr)Root)->Cluster.size())
	{
		// non trivial set
		NNodePtr p = (NNodePtr)Root;
		NNodePtr q = (NNodePtr)(p->GetChild());
        bool done = false;
		SetRelations r;

		// locate insertion point
		while (q && !done)
		{
			r = Relationship (b, q->Cluster);

			switch (r)
			{
				case IDENTITY:
					done = true;
					Error = 1; // we already have this cluster
					break;

				case SUBSET:
					p = q;
					q = (NNodePtr)(q->GetChild());
					break;

				case DISJOINT:
					p = q;
					q = (NNodePtr)(q->GetSibling());
					break;

				case SUPERSET:
					done = true;
					break;

				case OVERLAPPING:
					done = true;
					Error = 2; // can't be a part of a tree
					break;

				default:
					break;
			}
		}

		if (Error == 0)
		{
			// Create node
			NNodePtr nunode = (NNodePtr)NewNode ();
			Internals++;
			nunode->SetWeight(n);
			nunode->Cluster = b;

			if (label)
				nunode->SetLabel (label);


			// Insert node in tree
			switch (r)
			{
				case SUBSET:
                	p->SetChild (nunode);
                    nunode->SetAnc (p);
					break;

				case DISJOINT:
					p->SetSibling (nunode);
                    nunode->SetAnc (p->GetAnc());
					break;

				case SUPERSET:
					if (q == p->GetChild())
					{
                    	p->SetChild (nunode);
                        nunode->SetChild (q);
                        nunode->SetAnc (p);
                        q->SetAnc (nunode);
					}
					else
					{
	                   	p->SetSibling (nunode);
                        nunode->SetChild (q);
                        nunode->SetAnc (p->GetAnc());
                        q->SetAnc (nunode);
					}

                    NNodePtr tmp = q;
                    NNodePtr s = (NNodePtr)(q->GetSibling());
                    NNodePtr t = (NNodePtr)(q->GetAnc());

                    while (s)
                    {
                    	r = Relationship (s->Cluster, b);
                        if ((r == IDENTITY) || (r == SUBSET))
                        {
                        	s->SetAnc(nunode);
                            tmp = s;
                            s = (NNodePtr)(s->GetSibling());
                        }
                        else
                        {
                        	t->SetSibling (s);
                            tmp->SetSibling (s->GetSibling());
                            t = s;
                            t->SetSibling (NULL);
                            s = (NNodePtr)(tmp->GetSibling());
                       }
                    }
                    break;

//					checkSiblings (q, nunode->cluster);
				}
//			nunode->GetDegreeOf ();
//			nunode->anc->degree = nunode->degree - nunode->degree - 1;
		}
	}
	return Error;
}
//
// Neighborhood(s)
// Last modified: 29Nov2009
//
// Copy constructor that copies the contents of the
// parameterized list of states into this neighborhood.
//
// Returns:     <none>
// Parameters:
//      s       in/out      the list of states being copied
//
Neighborhood::Neighborhood(const vector<State> &s)
{
    for (GLint i = 0; i < s.size(); ++i) addNbr(Relationship(), s[i]);
}   // Neighborhood(const vector<State> &)