Esempio n. 1
0
EdgeInfo Pgr_trspHandler::dijkstra_exploration() {
    EdgeInfo cur_edge;
    pgassert(current_node == m_start_vertex);

    while (!que.empty()) {
        auto cur_pos = que.top();
        que.pop();

        auto cure_idxex = cur_pos.second.first;
        cur_edge = m_edges[cure_idxex];

        if (cur_pos.second.second) {
            /*
             * explore edges connected to end node
             */
            current_node = cur_edge.endNode();
            if (cur_edge.cost() < 0.0) continue;
            if (current_node == m_end_vertex) break;
            explore(current_node, cur_edge, false);
        } else {
            /*
             *  explore edges connected to start node
             */
            current_node = cur_edge.startNode();
            if (cur_edge.r_cost() < 0.0) continue;
            if (current_node == m_end_vertex) break;
            explore(current_node, cur_edge, true);
        }
    }
    return cur_edge;
}
Esempio n. 2
0
/* Self-referencing function that explores the maze recursively returning 1/0 on success/failure */
int explore(int x, int y, max_maze array, maze_dimensions dims){	

	// Bounds check (avoid seg fault)
	if (x >= dims.width || y >= dims.height || y < 0 || x < 0){
		return 0;
	}

	// Base case: cell is THE exit
	if ( onEdge(x,y,dims) && array[y][x] == ' '){	
		array[y][x]='.';
		return 1;
	}

	// Base case: cell is wall OR the cell we just came from
	if (array[y][x] == '#' || array[y][x] == '.'){
		return 0;
	}

	// Cell is neither exit nor wall. Drop a breadcrumb and keep going.
	array[y][x] = '.'; 

	// Try going EAST-WEST-NORTH-SOUTH...
	if (explore(x+1, y, array, dims)) {return 1;}
	if (explore(x-1, y, array, dims)) {return 1;}
	if (explore(x, y-1, array, dims)) {return 1;}
	if (explore(x, y+1, array, dims)) {return 1;}

	// Dead ends all around us, pick up the breadcrumb and return 0
	array[y][x] = ' ';
	return 0;
}
 void mineField::exploreNbours(const square &s)
 {
    assert(squareInsideMap(s));

    int t = s.row - 1, tSafe = s.row >               0, // Top    is within map.
        b = s.row + 1, bSafe = s.row < getHeight() - 1, // Bottom is within map.
        l = s.col - 1, lSafe = s.col >               0, // Left   is within map.
        r = s.col + 1, rSafe = s.col < getWidth()  - 1; // Right  is within map.

    if (tSafe)
    {
       if (lSafe) {explore(t, l    );} // Top left.
                  {explore(t, s.col);} // Top middle.
       if (rSafe) {explore(t, r    );} // Top right.
    }

       if (lSafe) {explore(s.row, l);} // Middle left.
       if (rSafe) {explore(s.row, r);} // Middle right.

    if (bSafe)
    {
       if (lSafe) {explore(b, l    );} // Bottom left.
                  {explore(b, s.col);} // Bottom middle.
       if (rSafe) {explore(b, r    );} // Bottom right.
    }
 }
Esempio n. 4
0
bool DAGraph::explore(int vertex, bool *visited){
	
	visited[vertex] = true;
	preVisit(vertex);
	std::list<StarLink*> &linksList = (nodes_[vertex])->outLinks;
	int index = -1;
	bool backEdgeDetected = false;
	StarLink* link = NULL;
	for(std::list<StarLink*>::iterator it = linksList.begin(); it != linksList.end(); ++it){
		link = *it;
		index = link->getNodeToIndex();
		if (checkPositiveFlow(link->getIndex())) {
			handleExploredLink(link);
			if ((nodes_[index])->pre == 0) {
				backEdgeDetected = explore(index, visited);
				if (backEdgeDetected) return true;
			}
			if ((nodes_[index])->pre > 0 && (nodes_[index])->post == 0) {
				return handleBackEdge(link);
			}
		} 
	}
	postVisit(vertex);
	return false;
};
Esempio n. 5
0
bool DAGraph::topologicalSort(){

	clock_ = 1;
	topOrder_.clear();
	int nbNodes = net_->getNbNodes(); 
	bool visited[nbNodes];
	for (int i = 0; i < nbNodes; ++i) {
		visited[i] = false;
	}
	int index = -1;
	for (int i = 0; i < nodeSize_; ++i) {
		index = nodeIndexes_[i];
		(nodes_[index])->pre = 0;
		(nodes_[index])->post = 0;
	}
	
	
	for (int i = 0; i < nodeSize_; ++i) {
		index = nodeIndexes_[i];
		if (!visited[index]) {
			bool tmp = explore(index, visited);
			if (tmp == true) {
				return true;
			}
		}
	}
	return false;
	
};
Esempio n. 6
0
void TankAI::brainTick(float seconds) {

	//listen closely and watch out for enemies.
	sense();

	//take a decision
	if (_currentTarget == NULL && _strategy != EXPLORE) {
		switchStrategy(EXPLORE, NULL);
	} else if (_currentTarget != NULL && _strategy != HUNT) {
		switchStrategy(HUNT, _currentTarget);
		delete _path;
		_path = NULL;
	}

	//do what you decided to do
	switch (_strategy) {
	case HUNT: {
		hunt();
		break;
	}
	case EXPLORE: {
		explore();
		break;
	}
	case ESCAPE: {
		escape();
		break;
	}
	}

}
Esempio n. 7
0
void simulatort::run(queuet &queue)
{
  fine_timet start_time=current_time();

  error_state_found=false;

  #ifdef DEBUG
  std::cout << "simulatort::run1\n";
  #endif

  unsigned counter=0;

  state_projectiont state_projection(formula_container, program_formula);
  
  while(!queue.empty() && !error_state_found)
  {
    #ifdef DEBUG
    std::cout << "simulatort::run2\n";
    #endif

    counter++;
    explore(queue.next(), queue);
  }

  if(error_state_found)
    std::cout << "VERIFICATION FAILED" << std::endl;
  else
    std::cout << "VERIFICATION SUCCESSFUL" << std::endl;

  std::cout << std::endl;
  std::cout << "States explored: " << counter << std::endl;
  std::cout << "Runtime: ";
  output_time(current_time()-start_time, std::cout);
  std::cout << std::endl;
}
Esempio n. 8
0
void explore(int r)
{
	int i;
	if (r == N)
	{
		count++;
		return; }


	for (i = 0; i < N; i++)
	{
		if (!dont[r][i] && !col[i] && !Sdiag[i + r] && !Ddiag[i - r + N - 1])
		{
			col[i]++;
			 Sdiag[i + r]++;
			  Ddiag[i - r + N - 1]++;
			explore(r + 1);
			col[i] = 0;
			Sdiag[i + r] = 0;
			 Ddiag[i - r + N - 1] = 0;
		}
	}


}
Esempio n. 9
0
//This method executes the policy
pair<vector<float>,float> CDACN::policy(const Window &window)
{
	if(uniform_real(engine)<exploration_rate_ or not window.full())
		return explore();
	else
		return exploit(window);
}
Esempio n. 10
0
void explore(int v)
{

	int i;
	int degree= 0;   // This is the number of direct children of this node

	number[v] = count++; 
	visited[v] = true;
	low[v] = number[v];   // Low keeps track of the lowest-index direct
						  // ancestor that can be reached from v or its children.
	bool go_up = true;
	
	for (i = 0; i < N; i++)
		if (graph[v][i] && !visited[i])
		{
			

			degree++;

			explore(i);
			
			if (low[i] >= number[v])
			{
				// If the highest-up parent that this child is connected to
				// is just v, then v is essential for the child's connectedness
				go_up = false;
			}

			//  If a child is connected higher up than me, then update my low value
			if (low[i] < low[v])
				low[v] = low[i];

			
		}

	for (i = 0; i < N; i++)
		if (graph[v][i] && visited[i])
		{
			//  If there is backedge to somebody higher up than I've seen so far,
			//   make my low value the number of that ancestor
			if (number[i] < low[v])
				low[v] = number[i];

		}

	/**** This assumes that the explore starts with 0 ****/
		//  Should not be an issue but double-check with main() function. -VN
	if (v == 0 && degree==1)
		art[v] = false;   // Root is special---articulation iff two or more children
	else if (v == 0 && degree > 1)
		art[v] = true;
	// Otherwise just use the go_up (do all my children go up) criterion
	else if (go_up)
		art[v] = false;
	else
		art[v] = true;

	

}
Esempio n. 11
0
/* Compute an attractor previously allocated by newAttractor */
void
computeAttractor (struct attractor *a, char *code)
{
    struct timeval t1, t2;

    if (code == NULL || checkCode (code)) {
        explore (a);
    }
    else {
        strncpy (a->code, code, a->polynom->length * a->dimension + 3);
        applyCode (a->polynom, code);
        if (!isAttractorConverging (a))
            fprintf (stderr, "Bad code - attractor not converging\n");
    }

    a->polynom->sum = getPolynomSum (a->polynom);

    displayPolynom (a->polynom);
    fprintf (stdout, "Lyapunov exponent: %.6f\n", a->lyapunov->ly);
    gettimeofday (&t1, NULL);
    iterateMap (a);
    gettimeofday (&t2, NULL);
    diffTime ("Map iteration", &t1, &t2);
    a->r = getRadius (a);
    centerAttractor (a);
    computeDimension (a);
    fprintf (stdout, "Correlation dimension: %.6f\n",
             a->correlationDimension);
    fprintf (stdout, "Code: %s\n", a->code);
}
Esempio n. 12
0
 pNode* cloneGraph(pNode* node) {
     if(node==NULL)
         return node;
         
     unordered_map<int, pNode*> gMap;
     return explore(node, gMap);
 }
Esempio n. 13
0
      Eigen::VectorXd explore(int dim,
                              const AcquisitionFunction& acqui,
                              const Eigen::VectorXd& current,
                              Eigen::VectorXd& result) const {
        double best_fit = -std::numeric_limits<double>::max();

        Eigen::VectorXd current_result(result.size());
        for (double x = 0; x <= 1; x += 1 / (double)nb_pts) {
          Eigen::VectorXd point = current;
          point[dim] = x;
          double val;
          if (dim == current.size() - 1) {
            val = acqui(point);
            if (val > best_fit) {
              best_fit = val;
              current_result = point;
            }
          } else {
            Eigen::VectorXd temp_result = current_result;
            std::tie(temp_result, val) = explore(dim + 1, acqui, point, temp_result);
            if (val > best_fit) {
              best_fit = val;
              current_result = temp_result;
            }
          }
        }
        return current_result;
      }
Esempio n. 14
0
void dfsx0 (graphe *pg, int x0, int suffixe[]){

    int marque[MAX_VERTEX_NUM], k,j;
    for (j=0; j < pg->n; j++)
	marque[j]= 0;
    k=0;
    explore(pg,x0,marque,suffixe,k);
    return;
}
Esempio n. 15
0
void play(void) {
	/*points[CAPTURE] = 100;
	points[DUMP]	= 40;
	points[EXPLORE]	= 30;
	points[MINE]	= 40;*/

    act = ACT_EXPLORE;


	//main game loop
	while(true) {
		switch(act) {
			case ACT_EXPLORE:
				mined_balls = 0;
                explore();
				act = 1;
				break;
			case ACT_PLAY:
				//circle finished to 20s left, dump balls if too many.
				vps_update();
				if(vps_get_owner(bot.territory)!=team) {		//if not ours yet
					capture(bot.territory);			//capture it
				}
                else if(vps_get_balls(bot.territory)>0) {	//if it is ours and there are balls
					mine(bot.territory);						//get the balls
				}
                else if(mined_balls>=15){
                    act = 2;
                }
                else {
					//move to different territory NOT containg opponent
					go_territory(get_best(), MOVE_SPEED);
				}
				break;
			case ACT_DUMP:
				if(team==TEAM_BLUE) {
					if(bot.territory>=3)
						score(bot.territory);
					else if(bot.territory==2)
						score(3);
					else
						score(5);
				} else {
					if(bot.territory<3)
						score(bot.territory);
					else if(bot.territory==3)
						score(2);
					else
						score(0);
				}
				//TODO emergency ball dump before end
				//dump balls anyway even if we think we don't have any?
                act = 1;
				break;
		}
	}
}
Esempio n. 16
0
    void solve(std::vector<std::vector<char>>&board) {
        if (board.size() == 0) {
            return;
        }

        // Top row
        for (int j = 0; j < board[0].size(); j++) {
            if (board[0][j] == 'O') {
                explore(board, 0, j);
            }
        }

        // Bottom row
        for (int j = 0; j < board[board.size() - 1].size(); j++) {
            if (board[board.size() - 1][j] == 'O') {
                explore(board, board.size() - 1, j);
            }
        }

        // Left column
        for (int i = 0; i < board.size(); i++) {
            if (board[i][0] == 'O') {
                explore(board, i, 0);
            }
        }

        // Right column
        for (int i = 0; i < board.size(); i++) {
            if (board[i][board[0].size() - 1] == 'O') {
                explore(board, i, board[0].size() - 1);
            }
        }

        // Relabeling
        for (int i = 0; i < board.size(); i++) {
            for (int j = 0; j < board[i].size(); j++) {
                if (board[i][j] == 'P') {
                    board[i][j] = 'O';
                } else {
                    board[i][j] = 'X';
                }
            }
        }
    }
Esempio n. 17
0
void OutputCluster::explore( const unsigned& index, const unsigned& depth ) {
  if( depth==0 ) return ;

  for(unsigned i=0; i<nneigh[index]; ++i) {
    unsigned j=adj_list(index,i); visited[j]=true;
    Vector svec=myclusters->pbcDistance( atomsin[index], atomsin[j] );
    atomsin[j] = atomsin[index] + svec;
    explore( j, depth-1 );
  }
}
/* Is there a row in any direction starting at [r][c]?
 */
int
rowformed(c4_t board, int r, int c) {
	return
		explore(board, r, c, +1,  0) ||
		explore(board, r, c, -1,  0) ||
		explore(board, r, c,  0, +1) ||
		explore(board, r, c,  0, -1) ||
		explore(board, r, c, -1, -1) ||
		explore(board, r, c, -1, +1) ||
		explore(board, r, c, +1, -1) ||
		explore(board, r, c, +1, +1);
}
Esempio n. 19
0
/* Fonction utilisée directement par la bibliothèque readline. Elle
   est utilisée pour récupérer les différentes possibilités de
   completion *pour les mots du trie*. Le mot à compléter est
   text. Lorsque la fonction est appellée pour la première fois, state
   == 0. Elle calcule alors les différentes colpmétions possibles
   grâce à explore(). words_generator() est ensuite appellée plusieurs
   fois, et doit retourner à chaque appel une nouvelle possibilité de
   completion (qu'elle pioche parmi celles précalculées). Quand il n'y
   en a plus, elle retourne NULL. Les complétions sont libérées par la
   bibliothèque readline */
char* words_generator(const char* text, int state) {
  /* Grâce au mot clef static, la valeur de list est conservée d'un
     appel sur l'autre */
  static Words* list;

  if(state == 0) {
    Trie* t = env.towns;
    Word* acc = NULL;
    list = NULL;
    int i;

    if(t == NULL || t->letters == NULL)
      return NULL;

    /* Calcul de l'accumulateur initial acc, correspondant aux lettres
       du préfixe que l'on nous a donné (text). On parcourt donc le
       trie, jusqu'à obtenir le sous-trie qu'il faudra explorer pour
       connaître les possibilités de completion */
    for(i = 0; text[i] != '\0'; i++) {
      if(t == NULL || t->letters == NULL) {
	return NULL;
      } else {
	acc = cons(text[i], acc);
	Letter* l = trie_getLetter(t, text[i]);
	if(l == NULL) 
	  return NULL;
	t = l->next;
      }
    }

    if(t != NULL && t->is_word) {
      list = cons_word(to_string(acc), list);
    }
    list = explore(t, acc, list);
  
    while(acc != NULL) {
      Word* n = acc->tail;
      free(acc);
      acc = n;
    }
  }

  /* À chaque appel, on retourne une nouvelle possibilité de
     completion en avançant dans list */
  while(list != NULL) {
    char* w = list->word;
    Words* tail = list->tail;
    free(list);    
    list = tail;

    return w;
  }

  return NULL;
}
Esempio n. 20
0
bool canReachBed(int n, int s1, int s2, int d1, int d2, std::list<int> o) {
	Graph<tile> g;
	set_graph(g, n);

	set_food(g, o, n);
	tile start; start.insert(s1); start.insert(s2);
	explore(g, start);

	tile end; end.insert(d1); end.insert(d2);
	return g.vertices[end]->visited;
}
Esempio n. 21
0
int djikstra(int ** vertices, int size, int start, int end)
{
    //printf("int djikstra( [%p], [%d], [%d], [%d]);", vertices, size, start, end);
    int * explored = malloc(size * sizeof(int));
    int * distance = malloc(size * sizeof(int));
    int ** path = malloc(size * sizeof(int *));
    int x, y, current;
    for (x = 0; x < size; x++)
    {
        path[x] = malloc(size * sizeof(int));
        for (y = 0; y < size; y++)
            path[x][y] = -1;
    }
    djikstra_fix(vertices, path, size);
    for (x = 0; x < size; x++)
    {
        explored[x] = 0; // unexplored
        distance[x] = INFINITY;
    }
    print(vertices, size, "vertices");
    printl(explored, size, "explored");
    printl(distance, size, "distance");
    int ishortest, shortest, curdis, newdis;
    current = start;
    explored[start] = 1;
    distance[start] = 0;
    ishortest = start;    
    while (!explore(explored, size))
    {
        shortest = INFINITY;
        curdis = distance[current];
        for (x = 0; x < size; x++)
        {
            if (!explored[x])
            {
                if (vertices[current][x] == INFINITY)
                    newdis = INFINITY;
                else
                    newdis = curdis + vertices[current][x];
                if (newdis < distance[x])
                    distance[x] = newdis;
                if (distance[x] < shortest)
                {
                    shortest = distance[x];
                    ishortest = x;
                }
            }
        }
        current = ishortest;
        explored[current] = 1;
        printl(distance, size, "distance");
    }
    print(path, size, "path");
}
Esempio n. 22
0
int search(int ys,int xs,int k)
{
    int x,y,found = 0;
    if (k==0) {
        int cnt = explore(nbr);
        found = cnt*nbr == sum;
    } else {
        for (y=ys;y<h && !found;y++)
            for (x=(y==ys?xs:0);x<w && !found;x++)
                if (mz[y][x]=='X') {
                    rel[nbr-k].y = y;
                    rel[nbr-k].x = x;
					//printf("k=%d x=%d y=%d\n",k,x,y);
					if (explore(nbr-k+1)*nbr>=sum)   
						found = search(y,x+1,k-1);    
                    if (k==nbr) return found;
                }
    }
    return found;
}
Esempio n. 23
0
vespalib::string explore(const StateExplorer &state, const vespalib::string &host,
                         const std::vector<vespalib::string> &items, size_t pos) {
    if (pos == items.size()) {
        return render(state, Url(host, items));
    }
    std::unique_ptr<StateExplorer> child = state.get_child(items[pos]);
    if (!child) {
        return "";
    }
    return explore(*child, host, items, pos + 1);
}
Esempio n. 24
0
 void explore(vector<vector<int>> &prerequistes, vector<bool> &visited, vector<int> &postNum, int &myclock, int curNode){
     if(visited[curNode]){
         return;
     }
     visited[curNode] = true;
     for(int i=0; i<prerequistes[curNode].size(); i++){
         explore(prerequistes, visited, postNum, myclock, prerequistes[curNode][i]);
     }
     myclock++;
     postNum[curNode] = myclock;
     return;
 }
Esempio n. 25
0
 pNode* explore(pNode* node, unordered_map<int, pNode*>& gMap) {
     pNode* u = new pNode(node->label);
     gMap.insert(std::pair<int, pNode*>(node->label, u));
     for(pNode* n: node->neighbors) {
         int i = gMap.count(n->label); 
         if(i>0)
             u->neighbors.push_back(gMap[n->label]);
         else
             u->neighbors.push_back(explore(n, gMap));
     }
     return u;
 }
Esempio n. 26
0
bool bm() {
  fill_n(visitedL, L, 0);
  for(int l = 0; l < L; l++)
    if(!matchedL[l] && explore(l)) {
      fill_n(visitedL, L, 0);
      matchedL[l] = 1;
    }
  for(int l = 0; l < L; l++)
    if(!matchedL[l])
      return 0;
  return 1;
}
Esempio n. 27
0
    /*
     * Resets valid words collection and explores the board.
     * Adds all valid words to the validWords collection.
     */
    void Boggle::findAllWords(){

        cpuWords.clear();
        unordered_set<int> visited;

        for(int y = 0; y < BOARD_HEIGHT; y++){
            for(int x = 0; x < BOARD_WIDTH; x++){

                explore("", x, y, visited);
            }
        }
    }
Esempio n. 28
0
main()
{
	int i, j;

	cin >> N;
	assert(N<=MAXN);

	for (i = 0; i < N; i++)
		for (j = 0; j < N; j++)
		{
			int p;
			cin >> p;
			G[i][j] = p ? true : false;
			T[j][i] = G[i][j];
		}

	for (i = 0; i < N; i++)
		visited[i] = false;

	count = -1;


	for (i = 0; i < N; i++)
		if (!visited[i])
			explore(i);

	for (i = 0; i < N; i++)
	{
		comp[i] = -1;
		visited[i] = false;
	}

	M = 0;


	for (i = 0; i < N; i++)
		if (!visited[index[i]])
		{
			// Found a new root, hence a new component.
			first[M] = index[i];
			// The first array stores the root of the component.
			comp[index[i]] = M++;
			exploreT(index[i]);
		}


	
	cout << M << endl;

	
return 0;
}
Esempio n. 29
0
/* When a folder is selected, use that as the new location of the other chooser. */
static void folder_changed (GtkFileChooser *chooser1, struct arguments *argument) {
    gchar *folder = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser1));
    GDir *dir = g_dir_open (folder, 0, NULL);
    FILE *list;
    list = fopen("list.txt", "w+");
    explore(dir, folder, list);
    float resnum = 0;
    char line[1000];
    int i;
    int count = 0, tmpcount;
    int rand;
    char *pline;

    rewind(list);
    for(; fgets(line, 1000, list) != NULL; ++count)
        ;

    tmpcount = count;

    while(resnum != 1 && tmpcount-- > 0) {
        free(current_sample_array);
        int rand = g_random_int_range(0, count);
        rewind(list);

        for(i = 0; i < rand; ++i)
            fgets(line, 1000, list);
        line[strcspn(line, "\n")] = '\0';

        resnum = analyze(line);
    }

    if (tmpcount > 0) {
        char artist[strlen(current_song.artist) + 9];
        char title[strlen(current_song.title) + 8];
        char album[strlen(current_song.album) + 8];
        strcpy(artist, "Artist: ");
        strcpy(title, "Title: ");
        strcpy(album, "Album: ");

        gtk_label_set_text((GtkLabel*)(((struct arguments*)argument)->label), "");
        gtk_label_set_text((GtkLabel*)(((struct arguments*)argument)->artist_label), strcat(artist, current_song.artist));
        gtk_label_set_text((GtkLabel*)(((struct arguments*)argument)->title_label), strcat(title, current_song.title));
        gtk_label_set_text((GtkLabel*)(((struct arguments*)argument)->album_label), strcat(album, current_song.album));

        gtk_adjustment_configure(((struct arguments*)argument)->adjust, 0, 0, current_song.duration, 1, 1, 1);
        ((struct arguments*)argument)->offset = 0;
        gtk_adjustment_changed(((struct arguments*)argument)->adjust);
    }
    else
        gtk_label_set_text((GtkLabel*)(((struct arguments*)argument)->label), "No calm songs found!");

}
Esempio n. 30
0
int DFSClustering::explore( const unsigned& index ) {

  color[index]=1;
  for(unsigned i=0; i<nneigh[index]; ++i) {
    unsigned j=adj_list(index,i);
    if( color[j]==0 ) color[j]=explore(j);
  }

  // Count the size of the cluster
  cluster_sizes[number_of_cluster].first++;
  which_cluster[index] = number_of_cluster;
  return color[index];
}