Exemple #1
0
// This method copies the graph to some other graph
void Graph<ValuesType>::copy_graph(Graph<ValuesType> &Target){
	Target.set_nodes_number(nodes_number);
	if (Graph_Matrix){
		Target.Set_Graph_Shape_Matrix();
	}
	else{Target.Set_Graph_Shape_List();
	};

	Target.Enable_Graph_Directed(Graph_Directed);
	Target.Enable_Graph_Weighted(Graph_Weighted);

	for (int i = 0; i < nodes_number; ++i){Target.set_node_value(i,nodes[i]);};
	for (int i = 0; i < edges_number; ++i){
		for (int j = 0; j < i; ++j){
			if (adjacent(i,j)){
				Target.add_edge(i,j,get_distance(i,j));Target.set_edge_value(i,j,get_edge_value(i,j));
			};
		};
		for (int j = i+1; j < edges_number; ++j){
			if (adjacent(i,j)){
				Target.add_edge(i,j,get_distance(i,j));Target.set_edge_value(i,j,get_edge_value(i,j));
			};
		};
	};
};
Exemple #2
0
//*****************************************************************************
//
//! @brief Get the wdt counter value.
//!
//! This function reads the current value of watch dog timer counter register.
//!
//! WARNING caller is responsible for masking interrutps before calling this
//! function.
//!
//! @return None
//
//*****************************************************************************
uint32_t
am_hal_wdt_counter_get(void)
{
  uint32_t ui32Values[3] = {0};
    uint32_t ui32Value;

    //
    // First, go read the value from the counter register 3 times
    // back to back in assembly language.
    //
    back2back_read_asm(ui32Values, (uint32_t *)AM_REG_WDTn(0));

    //
    // Now, we'll figure out which of the three values is the correct time.
    //
    if (ui32Values[0] == ui32Values[1])
    {
        //
        // If the first two values match, then neither one was a bad read.
        // We'll take this as the current time.
        //
        ui32Value = ui32Values[1];
    }
    else
    {
        //
        // If the first two values didn't match, then one of them might be bad.
        // If one of the first two values is bad, then the third one should
        // always be correct. We'll take the third value as the correct count.
        //
        ui32Value = ui32Values[2];

        //
        // If all of the statements about the architecture are true, the third
        // value should be correct, and it should always be within one count of
        // either the first or the second value.
        //
        // Just in case, we'll check against the previous two values to make
        // sure that our final answer was reasonable. If it isn't, we will
        // flag it as a "bad read", and fail this assert statement.
        //
        // This shouldn't ever happen, and it hasn't ever happened in any of
        // our tests so far.
        //
        am_hal_debug_assert_msg((adjacent(ui32Values[1], ui32Values[2]) ||
                                 adjacent(ui32Values[0], ui32Values[2])),
                                "Bad CDT read");
    }

    return ui32Value;
}
Exemple #3
0
int TopologyInfo::higher_order_from_side( EntityTopology topo,
                                          unsigned num_nodes,
                                          unsigned side_dimension,
                                          unsigned side_number,
                                          MsqError& err )
{
  bool mids[4] = { true };
  higher_order( topo, num_nodes, mids[1], mids[2], mids[3], err );
  MSQ_ERRZERO(err);
  
  if (side_dimension > dimension(topo) || 
      side_number > adjacent(topo, side_dimension)) {
    MSQ_SETERR(err)(MsqError::INVALID_ARG,"Invalid side number: %u\n", side_number );
    return 0;
  }
  
  if (!mids[side_dimension])
    return -1;
  
  int result = side_number;
  switch (side_dimension) {
    case 3: if (mids[2]) result += faces(topo);
    case 2: if (mids[1]) result += edges(topo);
    case 1: result += corners(topo);
    case 0: break;
    default: 
      MSQ_SETERR(err)(MsqError::INVALID_ARG,"Invalid dimension: %u\n", side_dimension );
      return 0;
  }
  return result;
}
Exemple #4
0
 DiGraph DiGraph::reverse() const {
     DiGraph dg(V());
     for(int v=0;v<V();++v)
         for(int w : adjacent(v))
             dg.addEdge(w,v);
     return dg;
 }
// Looks at all spaces within 2, looking for a spot which is clear of nastiness and beings
// returns {0,0} if none found
// THIS MAKES NO ADJUSTMENTS FOR BIG MONSTERS!!!
location find_clear_spot(location from_where,short mode)
//mode; // 0 - normal  1 - prefer adjacent space
{
	location loc,store_loc;
	short num_tries = 0,r1;
	
	while (num_tries < 75) {
		num_tries++;
		loc = from_where;
		r1 = get_ran(1,-2,2);
		loc.x = loc.x + r1;
		r1 = get_ran(1,-2,2);
		loc.y = loc.y + r1;
		if ((loc_off_act_area(loc) == false) && (is_blocked(loc) == false)
			&& (can_see(from_where,loc,1) == 0)
			&& (!(is_combat()) || (pc_there(loc) == 6))
			&& (!(is_town()) || (loc != univ.town.p_loc))
			 && (!(univ.town.misc_i(loc.x,loc.y) & 248)) && // check for crate, barrel, barrier, quickfire
			(!(univ.town.explored(loc.x,loc.y) & 254))) { // check for fields, clouds
				if ((mode == 0) || ((mode == 1) && (adjacent(from_where,loc) == true)))
					return loc;
					else store_loc = loc;			
				}
		}
	return store_loc;
}
Exemple #6
0
Vertex::~Vertex()
{
    for( auto connector_id : connection_set )
    {
        auto adjacent_vertex = adjacent(connector_id) ;
        if(adjacent_vertex) adjacent_vertex->connection_set.erase(connector_id) ;
    }
}
Exemple #7
0
void Vertex::add_connection( std::size_t connector_id )
{
    Vertex* adjacent_vertex = adjacent(connector_id) ;
    if(adjacent_vertex)
    {
        connection_set.insert(connector_id) ;
        adjacent_vertex->connection_set.insert(connector_id) ;
    }
}
Exemple #8
0
int HSolveUtils::adjacent( Id compartment, Id exclude, vector< Id >& ret )
{
	int size = ret.size();
	adjacent( compartment, ret );
	ret.erase(
		remove( ret.begin(), ret.end(), exclude ),
		ret.end()
	);
	return ret.size() - size;
}
Exemple #9
0
void pc_record_type::giveThing(short item_num)
{
	short who_to,how_many = 0;
	item_record_type item_store;
	bool take_given_item = true;
	short pc_num = getNum();

	if ((equip[item_num] == true) && (items[item_num].isCursed()))
			add_string_to_buf("Give: Item is cursed.           ");
  			else {
				item_store = items[item_num];
				who_to = char_select_pc(1,1,"Give item to who?");
				if ((overall_mode == MODE_COMBAT) && (adjacent(pc_pos[pc_num],pc_pos[who_to]) == false)) {
					add_string_to_buf("Give: Must be adjacent.");
					who_to = 6;
					}

				if ((who_to < 6) && (who_to != pc_num)
					&& ((overall_mode != MODE_COMBAT) || (adjacent(pc_pos[pc_num],pc_pos[who_to]) == true))) {
					if ((item_store.type_flag > 0) && (item_store.charges > 1)) {
						how_many = get_num_of_items(item_store.charges);
						if (how_many == 0)
							return;
						if (how_many < item_store.charges)
							take_given_item = false;
						items[item_num].charges -= how_many;
						item_store.charges = how_many;
						}
					if (adven[who_to].giveToPC(item_store,0) == true) {
						if (take_given_item) takeItem(item_num);
						}
						else {
							if (adven[who_to].hasSpace() == 24)
								ASB("Can't give: PC has max. # of items.");
								else ASB("Can't give: PC carrying too much.");
							if (how_many > 0)
								items[item_num].charges += how_many;
							}
				}
		}
}
Exemple #10
0
Fichier : 327.c Projet : treblih/oj
void inc_dec_2_spc()
{
	int ch;
	char *pos;
	for (; (ch = *p); p++) {
		if (ch == '+' && *(pos = adjacent(p, RIGHT)) == '+') {
			/* x  ++ */
			if (islower(ch = *adjacent(p, LEFT))) {
				alpha[ch - 0x61].inc_dec = 1;
			/* ++  x */
			} else if (islower(ch = *adjacent(pos, RIGHT))) {
				alpha[ch - 0x61].val += 1;
			}
			*p = *pos = ' ';/* clear the other '+' */
			p = pos;	/* p++ above */
		} else if (ch == '-' && *(pos = adjacent(p, RIGHT)) == '-') {
			/* x  ++ */
			if (islower(ch = *adjacent(p, LEFT))) {
				alpha[ch - 0x61].inc_dec = -1;
			/* ++  x */
			} else if (islower(ch = *adjacent(pos, RIGHT))) {
				alpha[ch - 0x61].val -= 1;
			}
			*p = *pos = ' ';/* clear the other '-' */
			p = pos;	/* p++ above */
		}
	}
}
Exemple #11
0
bool monst_adjacent(location loc,short m_num) {
	short i,j;
	location destination;
	
	for(i = 0; i < univ.town.monst[m_num].x_width; i++)
		for(j = 0; j < univ.town.monst[m_num].y_width; j++) {
			destination.x = univ.town.monst[m_num].cur_loc.x + i;
			destination.y = univ.town.monst[m_num].cur_loc.y + j;
			if(adjacent(destination,loc))
				return true;
		}
	return false;
}
Exemple #12
0
 void ChunkModelFactory::create_models(const std::vector<Vector3i> &positions,
                                       const World &world) {
     {
         std::lock_guard<std::mutex> lock(mutex);
         for(auto position: positions) {
             for(auto m : adjacent(position, world)) {
                 chunks.insert(m.position);
                 model_data.erase(m.position);
                 model_data.insert({m.position, m});
             }
         }
     }
     chunks_condition.notify_all();
 }
Exemple #13
0
std::vector<Direction::Value> Weave::AdjacentLeyRooms(const ROOM_INDEX_DATA & room, const void * id)
{
    // Iterate the rooms coming from this one
    std::vector<Direction::Value> result;
    for (unsigned int i(0); i < Direction::Max; ++i)
    {
        // Check whether there is a valid room in this direction which matches this ley id
        Direction::Value value(static_cast<Direction::Value>(i));
        ROOM_INDEX_DATA * adjacent(Direction::Adjacent(room, value));
        if (adjacent != NULL && adjacent->ley_group != NULL 
        && ((adjacent->ley_group->HasFount() && adjacent == id) || adjacent->ley_group->LineByID(id) != LeyGroup::NotFound))
            result.push_back(value);
    }
    return result;
}
static int should_combine( CondorChunk *a, CondorChunk *b )
{
	return
		overlaps(a,b)
		||
		(	a->dirty
			&&
			b->dirty
			&&
			( (a->size+b->size) <= a->max_size )
			&&
			adjacent(a,b)
		)
		;
}
Exemple #15
0
/*
* Removes the directed edge (u, v)
* If successful, return 1
* If u or v or edge does not exist, return 0
* If digraph is null, return -1
*/
int edge_remove( DiGraph DG, vertex u, vertex v )
{
   if (DG == NULL)
   {
       return -1;       
   }
   if ( u > (DG -> nVertices) - 1 
     || v > (DG -> nVertices) - 1 
     || adjacent( DG, u, v ) != 1 ) // u or v or edge does not exist on digraph
   {
       return 0;
   }
   else
   {
       --(DG -> inDegree)[v]; // decrease indegree of v
       return Aremove( v, &DG -> L[u] ); // remove the directed edge if possible
   }
}
Exemple #16
0
void seek_and_destroy() {
	if (!game.player.target) {
		// acquire a target
		u16 mindist = 16;
		Creature *candidate = 0;
		for (int y = game.player.y-4; y < game.player.y+4; y++)
			for (int x = game.player.x-4; x < game.player.x+4; x++) {
				u16 dist = dist2(x,y,game.player.x,game.player.y);
				if (dist <= 16 && game.map.occupied(x,y) &&
				    !(x == game.player.x && y == game.player.y) &&
				    game.map.block.at(x,y)->visible) {
				  // try to select aggressive creatures over peaceful ones
				  Creature *considered = game.map.at(x,y)->creature;
				  if (!candidate) candidate = considered;
					else if ((candidate->desc()->peaceful && !considered->desc()->peaceful) || dist < mindist) {
				  	candidate = considered;
				  	mindist = dist;
					}
				}
			}
		if (candidate) game.player.target = candidate;
	}
	if (game.player.target) {
		s16 targx = game.player.target->x, targy = game.player.target->y;
		if (dist2(game.player.x,game.player.y,targx,targy) > 16) {
			game.player.target = NULL; return;
		}
		if (!game.map.block.at(targx,targy)->visible) {
			game.player.target = NULL; return;
		}
		if (adjacent(targx,targy,game.player.x,game.player.y)) {
			if (you_hit_monster(game.player.target))
				game.player.target = NULL;
			game.cooldown += 5;
			return;
		} else {
			bresenstate st(game.player.x, game.player.y, targx, targy);
			st.step();
			game.player.moveDir(direction(st.posx(), st.posy(), game.player.x, game.player.y), true);
		}
	}
}
Exemple #17
0
	double Repulsion::computeCoordEnergy(
		node v1,
		node v2,
		const DPoint &p1,
		const DPoint &p2)
		const
	{
		double energy = 0;
		if(!adjacent(v1,v2)) {
			IntersectionRectangle i1 = shape(v1);
			IntersectionRectangle i2 = shape(v2);
			i1.move(p1);
			i2.move(p2);
			double dist = i1.distance(i2);
			OGDF_ASSERT(dist >= 0.0);
			double div = (dist+1.0)*(dist+1.0);
			energy = 1.0/div;
		}
		return energy;
	}
Exemple #18
0
void bfs_demo() {
	auto a = std::make_unique<TNode>('a');
	auto b = std::make_unique<TNode>('b');
	auto c = std::make_unique<TNode>('c');
	auto d = std::make_unique<TNode>('d');
	auto e = std::make_unique<TNode>('e');
	auto f = std::make_unique<TNode>('f');
	auto g = std::make_unique<TNode>('g');

	a->set_adjacent({b.get(), c.get()});
	b->set_adjacent({a.get(), d.get(), e.get()});
	c->set_adjacent({a.get(), f.get(), g.get()});
	d->set_adjacent({b.get()});
	e->set_adjacent({b.get(), f.get()});
	f->set_adjacent({c.get(), e.get()});
	g->set_adjacent({c.get()});


	// Trace all reachable nodes
	auto &start = a;
	std::queue<TNode *> q;
	q.push(start.get());
	start->visit();

	while (!q.empty()) {
		auto n = q.front();
		q.pop();
		std::cout << "Visit: " << n->get_data() << std::endl;
		for (auto cur: n->adjacent()) {
			if (!cur->is_visited()) {
				q.push(cur);
				cur->visit();
			}
		}
	}
	std::cout << std::endl;
}
Exemple #19
0
void MakeMap( void )
{
  int x, y, color;

  for (y = 0; y < YMAX; y++)
    for (x = 0; x < XMAX; x++)
    {
      color = getpixel( y, x);
      switch (color)
      {
        case BLACK:
          if (adjacent( x, y, BROWN) > 1)
            gWorld[ x][ y] = terrain[ 21]; /* D”rr */
          else
            gWorld[ x][ y] = terrain[ 13]; /* Port */
          break;

        case DARKGREEN:
          gWorld[ x][ y] = terrain[ 4]; /* Gr„s */
          break;
          
        case DARKBLUE:
          gWorld[ x][ y] = terrain[ 7]; /* H2O */
          break;
          
        case BLUE:
          if (adjacent( x, y, DARKBLUE) > 0)
            gWorld[ x][ y] = terrain[ 8]; /* Stenar i vatten */
          else
            gWorld[ x][ y] = terrain[ 1]; /* Stenplatta */
          break;

        case DARKBROWN:
          gWorld[ x][ y] = terrain[ 0]; /* Jord */
          break;
          
        case RED:
          if (adjacent( x, y, YELLOW) != 0 || adjacent( x, y, DARKGREEN) != 0)
            gWorld[ x][ y] = terrain[ 6]; /* R”d blomma */
          else
            gWorld[ x][ y] = terrain[ 14]; /* Tr„golv */
          break;
          
        case YELLOW:
          if (adjacent( x, y, YELLOW) < 2 || adjacent( x, y, RED) > 1)
            gWorld[ x][ y] = terrain[ 5]; /* Gul blomma */
          else
            gWorld[ x][ y] = terrain[ 12]; /* Sand */
          break;
          
        case BEIGE:
          gWorld[ x][ y] = terrain[ 19]; /* Buske */
          break;
          
        case GREEN:
          if (adjacent( x, y, YELLOW) > 2)
            gWorld[ x][ y] = terrain[ 11]; /* Palm */
          else if (adjacent( x, y, DARKBLUE) > 1)
            gWorld[ x][ y] = terrain[ 9]; /* Sankmark */
          else
            gWorld[ x][ y] = terrain[ 10]; /* Tr„d */
          break;
          
        case WHITE:
          if (adjacent( x, y, WHITE) != 0)
            gWorld[ x][ y] = terrain[ 16]; /* Stenmur */
          else
          {
            gWorld[ x][ y] = terrain[ 22]; /* Portal */
            if (MAX( ABS( x - 100), y) < MAX( ABS( gateX - 100), gateY))
            {
              gateX = x;
              gateY = y;
            }
          }
          break;
          
        case LIGHTGRAY:
          gWorld[ x][ y] = terrain[ 17]; /* Tegelv„gg */
          break;
          
        case DARKGRAY:
          gWorld[ x][ y] = terrain[ 18]; /* Berg */
          break;
          
        case DARKRED:
          gWorld[ x][ y] = terrain[ 2]; /* Grus */
          break;
          
        case ORANGE:
          gWorld[ x][ y] = terrain[ 15]; /* Plankor */
          break;
          
        case BROWN:
          gWorld[ x][ y] = terrain[ 20]; /* Tr„v„gg */
          break;
          
        case GRAY:
          gWorld[ x][ y] = terrain[ 3]; /* Stenplatta */
          break;
      }
    }
}
std::vector<comVec3> cycleSearch( std::vector<comVec3>& lines){
    if (lines.size()==0){
        return lines;
    }
    //2 pts in the lines vector gives an edge
    std::vector<comVec3>::iterator lit;

    std::vector<comVec3> cycles;

    std::set<comVec3> vertices;
    vertices.insert(lines.begin(), lines.end());
    
    std::vector<comVec3> v_vertices;
    std::vector<comVec3>::iterator vit = v_vertices.begin();
    vit = v_vertices.insert(vit, vertices.begin(), vertices.end());

    std::vector<int> edges (lines.size(), 0);
    std::vector<comVec3> cycle;

    for (int j=0; j<(int)v_vertices.size(); j++){
        for (int i=0; i<(int)lines.size(); i++){
            if (lines[i]==v_vertices[j]){
                edges[i]=j;
                //std::cout<<"hello";
            }
        }
    } 

    /*//cout edges
    for (int i=0; i<(int)lines.size(); i++){
        std::cout<<edges[i]<<" "<<glm::to_string(lines[i].content)<<std::endl;
    }*/
    
    std::stack<int> stacky;
    std::stack<int> history;
    std::stack<int> previouses;
    stacky.push(edges[0]);
    history.push(-1);
    history.push(edges[0]);
//DFS
    std::vector<bool> visited(vertices.size(), false);

    int previous = -1;
    int current = -1;

    while(stacky.size()!=0){
        previous = current;
        current = stacky.top();
        stacky.pop();

        /*//cout stacky and history
        std::cout<<"stacky: ";
        std::stack<int> temp;
        while (stacky.size()!=0){
            std::cout<<stacky.top();
            temp.push(stacky.top());
            stacky.pop();
        }
        while (temp.size()!=0){
            stacky.push(temp.top());
            temp.pop();
        }
        std::cout<<std::endl;
        std::cout<<"history: ";
        while (history.size()!=0){
            std::cout<<history.top();
            temp.push(history.top());
            history.pop();
        }
        while (temp.size()!=0){
            history.push(temp.top());
            temp.pop();
        }
        std::cout<<std::endl;*/

        if (visited[current]){
            std::vector<int> cyc= cyc_found(history, current, previous);
            std::vector<int>::iterator cit;
            int i = history.top();
            history.pop();
            while (i!= -1){
                visited[i] = false;
                i = history.top();
                history.pop();
                previouses.pop();
            }
            for (cit=cyc.begin(); cit!=cyc.end(); cit++){
                cycle.push_back(v_vertices[*cit]);
            }

        }
        else{
            visited[current] = true;
            if (!adjacent(edges, stacky, history, previouses, current, previous)){
                int i = history.top();
                history.pop();
                while (i!= -1){
                    visited[i] = false;
                    i = history.top();
                    history.pop();
                    previouses.pop();
                }
            }
        }
    }
        
    return cycle;
}
int 
DomainPartitioner::releaseVertex(int from, 
				 int vertexTag, 
				 Graph &theWeightedPartitionGraph,
				 bool mustReleaseToLighter,
				 double factorGreater,
				 bool adjacentVertexNotInOther)
{
  // check that the object did the partitioning
  if (partitionFlag == false) {
    opserr << "DomainPartitioner::balance(const Vector &load)";
    opserr << " - not partitioned or DomainPartitioner did not partition\n";
    return -1;
  }
  
  // we first check the vertex is on the fromBoundary
  Subdomain *fromSubdomain = myDomain->getSubdomainPtr(from);
  if (fromSubdomain == 0) {
    opserr << "DomainPartitioner::swapVertex - No from Subdomain: ";
    opserr << from << " exists\n";
    return -1;
  }

  // get the vertex from the boundary vertices of from
  // Graph &theEleGraph = myDomain->getElementGraph();    
  Graph *fromBoundary = theBoundaryElements[from-1];
    
  Vertex *vertexPtr = fromBoundary->getVertexPtr(vertexTag);
  if (vertexPtr == 0) 
    vertexPtr = theElementGraph->getVertexPtr(vertexTag);
  
  if (vertexPtr == 0)  // if still 0 no vertex given by tag exists
    return -3;

  ID attraction(numPartitions+1);
  attraction.Zero();

  // determine the attraction to the other partitions
  const ID &adjacent = vertexPtr->getAdjacency();
  int numAdjacent = adjacent.Size();
  for (int i=0; i<numAdjacent; i++) {
    int otherTag = adjacent(i);
    Vertex *otherVertex = theElementGraph->getVertexPtr(otherTag);
    int otherPartition = otherVertex->getColor();
    if (otherPartition != from)
      attraction(otherPartition) += 1;
  }
  
  // determine the other partition the vertex is most attracted to
  int partition = 1;
  int maxAttraction = attraction(1);
  for (int j=2; j<=numPartitions; j++)
    if (attraction(j) > maxAttraction) {
      partition = j;
      maxAttraction = attraction(j);
    }

  // swap the vertex
  if (mustReleaseToLighter == false)
    return swapVertex(from, partition, vertexTag, adjacentVertexNotInOther);
  
  else { // check the other partition has a lighter load
    Vertex *fromVertex = theWeightedPartitionGraph.getVertexPtr(from);
    Vertex *toVertex = theWeightedPartitionGraph.getVertexPtr(partition);	    
    
    double fromWeight = fromVertex->getWeight();
    double toWeight  = toVertex->getWeight();
    
    if (fromWeight == toWeight)
      opserr << "DomainPartitioner::releaseVertex - TO CHANGE >= to >\n";

    if (fromWeight >= toWeight) {
      if (toWeight == 0.0) 
	return swapVertex(from,partition,vertexTag,adjacentVertexNotInOther);	    
      if (fromWeight/toWeight > factorGreater)        
	return swapVertex(from,partition,vertexTag,adjacentVertexNotInOther);	    
    }
  }
  
  return 0;
}
Exemple #22
0
void Vertex::remove_connection( std::size_t connector_id )
{
    connection_set.erase(connector_id) ;
    Vertex* adjacent_vertex = adjacent(connector_id) ;
    if(adjacent_vertex) adjacent_vertex->connection_set.erase(connector_id) ;
}