Exemplo n.º 1
0
void iManaVtxCtlCnst::OnVisitorEnter(iHero* pHero)
{
	check(pHero);
	if (!Visited(pHero)) {
		DoubleManaPoints(pHero);
	}
}
Exemplo n.º 2
0
ISymbol::ISymbol()
{
	Parsed()=0; 
	Visited()=0; 
	Type()=(SymbolType) -1; 
	ListType()=unknown_; 
	Dimension()=0;
	SimpleType()=true;
	Required()=false;
	Abstract()=false;
	Compositor()=0;
	DerivedType() = XercesAdditions::DERIVATION_NONE;
	XercesType() = XercesAdditions::NO_DECLARATION;
	Global()=false;
	SqlCount()=0;
	SubstitutionGroupAffiliation().clear();
	symbols.push_back(this);
	Variable()=NULL;
	SimpleContent()=false;
	List()=false;
	Atomic()=false;
	Level()=0;
	ListSize()=0;
	intrusive_ptr_add_ref((IExpress *) symbols.back().get());
}
/*------------------------------------------------------------------
 * Function:        Feasible
 * Purpose:         Check whether nbr could possibly lead to a better
 *                  solution if it is added to the current tour.  The
 *                  functions checks whether nbr has already been visited
 *                  in the current tour, and, if not, whether adding the
 *                  edge from the current city to nbr will result in
 *                  a cost less than the current best cost.
 * In args:         All
 * Global vars in:  mat, n, best_tour
 * Local var in:    local_best_cost
 * Return:          TRUE if the nbr can be added to the current tour.
 *                  FALSE otherwise
 */
int Feasible(city_t city, city_t nbr, tour_t* tour_p, weight_t local_best_cost) {
    if (!Visited(nbr, tour_p) &&
         tour_p -> cost + mat[n*city + nbr] < local_best_cost) 
       return TRUE;
    else
       return FALSE;
}  /* Feasible */
Exemplo n.º 4
0
void iPermFSKModCtlCnst::OnVisitorEnter(iHero* pHero)
{
	check(pHero);
	if (!Visited(pHero)) {
		pHero->ConstFurtSkills().Value(skill) += mod;
		visitors.Add(pHero->Proto()->m_protoId);
	}
}
Exemplo n.º 5
0
/*------------------------------------------------------------------
 * Function:  Feasible
 * Purpose:   Check whether nbr could possibly lead to a better
 *            solution if it is added to the current tour.  The
 *            function checks whether nbr has already been visited
 *            in the current tour, and, if not, whether adding the
 *            edge from the current city to nbr will result in
 *            a cost less than the current best cost.
 * In args:   All
 * Global in:
 *    best_tour
 * Return:    TRUE if the nbr can be added to the current tour.
 *            FALSE otherwise
 */
int Feasible(tour_t tour, city_t city) {
   city_t last_city = Last_city(tour);

   if (!Visited(tour, city) && 
        Tour_cost(tour) + Cost(last_city,city) < Tour_cost(best_tour))
      return TRUE;
   else
      return FALSE;
}  /* Feasible */
Exemplo n.º 6
0
/// Get a sequential list of vertices for Start to Stop, if one exists
bool clGraph::FindPath( int Start, int Stop, LArray<int>& Path )
{
	Path.clear();

	/// Try one: BFS

	LArray<bool> Visited( FVertices.size() );
	bool* v = Visited.begin();

	for ( size_t p = 0 ; p < FVertices.size() ; p++ ) { *v++ = false; }

	/// stack for visited nodes
	LArray<int> Q;

	Path.push_back( Start );
	Path.push_back( Start ); // twic, because first is popped

	Q.push_back( Start );
	Visited[Start] = true;

	LArray<int> Adj;

	while ( !Q.empty() )
	{
		int x = Q.back();

		if ( x == Stop ) { return true; }

		Q.pop_back();
		Path.pop_back();

		GetAdjacent( x, Adj );

		int N = static_cast<int>( Adj.size() );

		for ( int i = 0 ; i < N ; i++ )
		{
			int v = Adj[i];

			if ( !Visited[v] )
			{
				Q.push_back( v );
				Visited[v] = true;
				Path.push_back( v );
			}
		}
	}

	return false;
}
Exemplo n.º 7
0
void ISymbol::MergeTypeInfo(ISymbolPtr c)
{
	c->TypeName() = Name();
	// Ignore, Name(), Namespace(), and Type()

	c->Abstract() = Abstract();
	c->Atomic() = Atomic();
	c->Attributes() = Attributes();
	c->BaseTypeName() = BaseTypeName();
	c->Compositor() = Compositor();
	c->DerivedType() = DerivedType();
	c->Enumerations() = Enumerations();
	c->FacetKinds() = FacetKinds();
	c->Facets() = Facets();
	c->Global() = Global();
	c->Level() = Level();
	c->List() = List();
	c->ListSize() = ListSize();
	c->ListType() = ListType();
	c->Optional() = Optional();
	c->Parent() = Parent();
	c->Parsed() = Parsed();
	c->PrimitiveType() = PrimitiveType();
	c->Required() = Required();
	c->SimpleContent() = SimpleContent();
	c->SimpleType() = SimpleType();
	c->SqlCount() = SqlCount();
	c->SqlType() = SqlType();
	c->SubstitutionGroupAffiliation() = SubstitutionGroupAffiliation();
	c->SubstitutionList() = SubstitutionList();
	c->SubTypes() = SubTypes();
	c->SuperTypes() =  SuperTypes();

	c->Variable() = Variable();
	c->Visited() = Visited();
	c->XercesType() = XercesType();
	
	// These are element particle definitions
	// c->Dimension() = Dimension(); // always 1
	//c->LowerBounds() = LowerBounds();
	//c->UpperBounds() = UpperBounds();
	//c->OuterElementName() = OuterElementName();
	// c->OuterElementTypeName() = OuterElementTypeName();

}
Exemplo n.º 8
0
void ISymbol::DeepCopy(ISymbolPtr c)
{
	c->Name()=Name();

	c->Abstract() = Abstract();
	c->Atomic() = Atomic();
	c->Attributes() = Attributes();
	c->BaseTypeName() = BaseTypeName();
	c->Compositor() = Compositor();
	c->DerivedType() = DerivedType();
	c->Dimension() = Dimension();
	c->Enumerations() = Enumerations();
	c->FacetKinds() = FacetKinds();
	c->Facets() = Facets();
	c->Global() = Global();
	c->Level() = Level();
	c->List() = List();
	c->ListSize() = ListSize();
	c->ListType() = ListType();
	c->LowerBounds() = LowerBounds();
	c->Namespace() = Namespace();
	c->Optional() = Optional();
	c->OuterElementName() = OuterElementName();
	c->OuterElementTypeName() = OuterElementTypeName();
	c->Parent() = Parent();
	c->Parsed() = Parsed();
	c->PrimitiveType() = PrimitiveType();
	c->Required() = Required();
	c->SimpleContent() = SimpleContent();
	c->SimpleType() = SimpleType();
	c->SqlCount() = SqlCount();
	c->SqlType() = SqlType();
	c->SubstitutionGroupAffiliation() = SubstitutionGroupAffiliation();
	c->SubstitutionList() = SubstitutionList();
	c->SubTypes() = SubTypes();
	c->SuperTypes() =  SuperTypes();
	c->Type() = Type();
	c->TypeName() = TypeName();
	c->UpperBounds() = UpperBounds();
	c->Variable() = Variable();
	c->Visited() = Visited();
	c->XercesType() = XercesType();
}
Exemplo n.º 9
0
Graph<T> Graph<T>::Kruskal( int vertex )
{
    const int V = GetVertices();
    Graph<int> MST( V );   
    MinPairHeap Heap;
    std::vector<bool> Visited( Matrix.size(), false );
    
    int current = vertex;
    Visited[current] = true;
    std::vector< std::pair<int,int> > neighbors =
	FindAllNeighbors( vertex );

    for( int i = 0; i < neighbors.size(); i++ )
    {
	Heap.push( neighbors[i] );
    }
    while( !Heap.empty() )
    {
	std::pair<int, int> Vert = Heap.pop();
	std::cout << Vert.first << std::endl;
    }
    
}
Exemplo n.º 10
0
VALUE DetermineZeroValue(POSITION position)
{
	POSITION i,lowSeen,highSeen;
	POSITION numUndecided, oldNumUndecided, numNew;
	MOVELIST *moveptr, *headMove;
	POSITION child;
	VALUE childValue;
	POSITION numTot, numWin, numTie;
	int tieRemoteness, winRemoteness;

	//if (gTwoBits)
	//    InitializeVisitedArray();

	StoreValueOfPosition(position,Primitive(position));
	MarkAsVisited(position);
	oldNumUndecided = 0;
	numUndecided = 1;
	numNew = 1;

	lowSeen = position;
	highSeen = lowSeen+1;

	while((numUndecided != oldNumUndecided) || (numNew != 0)) {

		oldNumUndecided = numUndecided;
		numUndecided = 0;
		numNew = 0;
		for(i = lowSeen; i <= highSeen; i++) {
			if(Visited(i)) {
				if(GetValueOfPosition(i) == undecided) {
					moveptr = headMove = GenerateMoves(i);
					numTot = numWin = numTie = 0;
					tieRemoteness = winRemoteness = REMOTENESS_MAX;
					while(moveptr != NULL) {
						child = DoMove(i,moveptr->move);
						numTot++;
						if(Visited(child))
							childValue = GetValueOfPosition(child);
						else{
							childValue = Primitive(child);
							numNew++;
							MarkAsVisited(child);
							StoreValueOfPosition(child,childValue);
							if(childValue != undecided) {
								SetRemoteness(child,0);
							}
							if(child < lowSeen) lowSeen = child;
							if(child > highSeen) highSeen = child + 1;
						}

						if(childValue == lose) {
							StoreValueOfPosition(i,win);
							if(Remoteness(i) > Remoteness(child)+1)
								SetRemoteness(i,Remoteness(child)+1);
						}

						if(childValue == win) {
							numWin++;
							if(Remoteness(child) < winRemoteness) {
								winRemoteness = Remoteness(child);
							}
						}
						if(childValue == tie) {
							numTie++;
							if(Remoteness(child) < tieRemoteness) {
								tieRemoteness = Remoteness(child);
							}
						}

						moveptr = moveptr->next;
					}
					FreeMoveList(headMove);
					if((numTot != 0) && (numTot == numWin + numTie)) {
						if(numTie == 0) {
							SetRemoteness(i, winRemoteness+1);
							StoreValueOfPosition(i,lose);
						}else{
							SetRemoteness(i, tieRemoteness+1);
							StoreValueOfPosition(i,tie);
						}
					}

					if(GetValueOfPosition(i) == undecided)
						numUndecided++;
				}
			}
		}

		printf("\nnumUndecided: " POSITION_FORMAT ", diff: " POSITION_FORMAT ", numNew: " POSITION_FORMAT
		       ", lowSeen: " POSITION_FORMAT ", highSeen: " POSITION_FORMAT,
		       numUndecided,numUndecided - oldNumUndecided,numNew,lowSeen,highSeen);

	}

	for(i = 0; i < gNumberOfPositions; i++) {
		if(Visited(i) && (GetValueOfPosition(i) == undecided)) {
			SetRemoteness(i,REMOTENESS_MAX);
			StoreValueOfPosition(i, tie);
		}
		UnMarkAsVisited(i);
	}

	return GetValueOfPosition(position);
}
Exemplo n.º 11
0
void WriteNode(FILE *fp, POSITION node, int level, EDGELIST *tree) {
	OPEN_POS_DATA pdata;
	REMOTENESS nodeRemoteness;
	char label[50];

	if(kLoopy && gUseOpen) {
		pdata = GetOpenData(node);
	} else {
		pdata = 0;
	}

	if(!Visited(node)) {
		if(level != GetLevelNumber(pdata)) {
			fprintf(fp, "\t\tsubgraph cluster%llu {\n", node);
			fprintf(fp, "\t\t\tlabel = \" \"\n");
			fprintf(fp, "\t\t\tcolor = \"blue\"\n\t");
			sprintf(label, "\\nlvl %d", GetLevelNumber(pdata));
		} else {
			sprintf(label, " ");
		}

		if(node == gInitialPosition) {
			if(level == GetLevelNumber(pdata)) {
				fprintf(fp, "\t\tsubgraph cluster%llu {\n", node);
				fprintf(fp, "\t\t\tcolor = \"blue\"\n\t");
			}
			fprintf(fp, "%slabel = \"Initial Position\"\n\t", (level == GetLevelNumber(pdata)) ? "\t\t\t" : "\t\t");
		}

		if(GetLevelNumber(pdata) == 0) {
			MarkAsVisited(node);
			fprintf(fp, "\t\t%llu [color = \"%s\", style = \"filled\", shape = \"%s\", label = \"%llu%s\"]", node, PositionColor(node), PositionShape(node), node, label);
		} else if(GetLevelNumber(pdata) > 0) {
			MarkAsVisited(node);
			fprintf(fp, "\t\t%llu [color = \"%s\", style = \"filled\", peripheries = %d, shape = \"%s\", label = \"%llu%s\"]", node, PositionColor(node), GetCorruptionLevel(pdata) + 1, PositionShape(node), node, label);
		} else {
			BadElse("WriteNode");
		}

		if(level != GetLevelNumber(pdata) || node == gInitialPosition) {
			fprintf(fp, "\n\t\t}\n");
		} else {
			fprintf(fp, "\n");
		}

		/* Determine rank of node */
		if(GetLevelNumber(pdata) == 0) {
			nodeRemoteness = Remoteness(node);
		} else {
			nodeRemoteness = GetFremoteness(pdata);
		}

		//0-REMOTENESS_MAX-1 regular nodes,
		//REMOTENESS_MAX level above current level,
		//REMOTENESS_MAX+1 level below current level
		if(gRemotenessOrder) {
			if(level == GetLevelNumber(pdata)) {
				if(GetFringe(pdata)) {
					UpdateRankList(tree, node, REMOTENESS_MAX+1); // want fringes at bottom
				} else {
					UpdateRankList(tree, node, nodeRemoteness);
				}
			} else if(level > GetLevelNumber(pdata)) {
				UpdateRankList(tree, node, REMOTENESS_MAX+1);
			} else if(level < GetLevelNumber(pdata)) {
				UpdateRankList(tree, node, REMOTENESS_MAX);
			} else {
				BadElse("WriteNode");
			}
		}
	}
}
Exemplo n.º 12
0
/** Ester, Kriegel, Sander, Xu; Proceedings of 2nd International Conference
  * on Knowledge Discovery and Data Mining (KDD-96); pp 226-231.
  */
int Cluster_DBSCAN::Cluster() {
  std::vector<int> NeighborPts;
  std::vector<int> Npts2; // Will hold neighbors of a neighbor
  std::vector<int> FramesToCluster;
  ClusterDist::Cframes cluster_frames;
  // First determine which frames are being clustered.
  // FIXME: Just use sieved array?
  for (int frame = 0; frame < (int)FrameDistances_.Nframes(); ++frame)
    if (!FrameDistances_.IgnoringRow( frame ))
      FramesToCluster.push_back( frame );
  // Calculate Kdist function
  if (!kdist_.Empty()) {
    if (kdist_.Size() == 1)
      ComputeKdist( kdist_.Front(), FramesToCluster );
    else
      ComputeKdistMap( kdist_, FramesToCluster );
    return 0;
  }
  // Set up array to keep track of points that have been visited.
  // Make it the size of FrameDistances so we can index into it. May
  // waste memory during sieving but makes code easier.
  std::vector<bool> Visited( FrameDistances_.Nframes(), false );
  // Set up array to keep track of whether points are noise or in a cluster.
  Status_.assign( FrameDistances_.Nframes(), UNASSIGNED);
  mprintf("\tStarting DBSCAN Clustering:\n");
  ProgressBar cluster_progress(FramesToCluster.size());
  int iteration = 0;
  for (std::vector<int>::iterator point = FramesToCluster.begin();
                                  point != FramesToCluster.end(); ++point)
  {
    if (!Visited[*point]) {
      // Mark this point as visited
      Visited[*point] = true;
      // Determine how many other points are near this point
      RegionQuery( NeighborPts, FramesToCluster, *point );
      if (debug_ > 0) {
        mprintf("\tPoint %i\n", *point + 1);
        mprintf("\t\t%u neighbors:", NeighborPts.size());
      }
      // If # of neighbors less than cutoff, noise; otherwise cluster
      if ((int)NeighborPts.size() < minPoints_) {
        if (debug_ > 0) mprintf(" NOISE\n");
        Status_[*point] = NOISE;
      } else {
        // Expand cluster
        cluster_frames.clear();
        cluster_frames.push_back( *point );
        // NOTE: Use index instead of iterator since NeighborPts may be
        //       modified inside this loop.
        unsigned int endidx = NeighborPts.size();
        for (unsigned int idx = 0; idx < endidx; ++idx) {
          int neighbor_pt = NeighborPts[idx];
          if (!Visited[neighbor_pt]) {
            if (debug_ > 0) mprintf(" %i", neighbor_pt + 1);
            // Mark this neighbor as visited
            Visited[neighbor_pt] = true;
            // Determine how many other points are near this neighbor
            RegionQuery( Npts2, FramesToCluster, neighbor_pt );
            if ((int)Npts2.size() >= minPoints_) {
              // Add other points to current neighbor list
              NeighborPts.insert( NeighborPts.end(), Npts2.begin(), Npts2.end() );
              endidx = NeighborPts.size();
            }
          }
          // If neighbor is not yet part of a cluster, add it to this one.
          if (Status_[neighbor_pt] != INCLUSTER) {
            cluster_frames.push_back( neighbor_pt );
            Status_[neighbor_pt] = INCLUSTER;
          }
        }
        // Remove duplicate frames
        // TODO: Take care of this in Renumber?
        std::sort(cluster_frames.begin(), cluster_frames.end());
        ClusterDist::Cframes::iterator it = std::unique(cluster_frames.begin(), 
                                                        cluster_frames.end());
        cluster_frames.resize( std::distance(cluster_frames.begin(),it) );
        // Add cluster to the list
        AddCluster( cluster_frames );
        if (debug_ > 0) {
          mprintf("\n");
          PrintClusters();
        }
      }
    }
    cluster_progress.Update(iteration++);
  } // END loop over FramesToCluster
  // Calculate the distances between each cluster based on centroids
  CalcClusterDistances();

  return 0;
}