Beispiel #1
0
int main(void) {
    preparation_t queries[] = {
        { "rate",
            "SELECT connectionStrength((select id from mode),$2,$1)" },
        { "getpage",
            "select strength,title,songs.id from connections inner join songs on connections.blue = songs.id where red = (select id from mode) order by strength desc OFFSET $1 LIMIT $2;" }
    };
    PQinit();
    gtk_init(NULL,NULL);
    prepareQueries(queries);

    GtkBuilder* builder = gtk_builder_new_from_string(gladeFile,gladeFileSize);
    GtkWidget* top = GTK_WIDGET(gtk_builder_get_object(builder,"top"));
    GtkTreeSelection* selection = GTK_TREE_SELECTION(
            gtk_builder_get_object(builder,"song-selection"));
    GtkButton* rateup = GTK_BUTTON(
            gtk_builder_get_object(builder,"rateup"));
    GtkButton* ratedown = GTK_BUTTON(
            gtk_builder_get_object(builder,"ratedown"));

    g_signal_connect(G_OBJECT(rateup),"clicked",G_CALLBACK(yay),selection);
    g_signal_connect(G_OBJECT(ratedown),"clicked",G_CALLBACK(nay),selection);

    GtkListStore* model = GTK_LIST_STORE(
            gtk_builder_get_object(builder,"songs"));

    fillNext(selection,model);
    gtk_widget_show_all(top);
    gtk_main();
}
Beispiel #2
0
void GRAPHmstP2 (Graph G, Vertex parnt[], double cst[]) {
    Vertex v, w, fr[maxV]; 
    link p;

    GRAPHmaxcst(G);

    for (v = 0; v < G->V; v++) {
        cst[v] = INFINITO;
        parnt[v] = -1;
    }
    PQinit(G->V);
    cst[0] = 0;
    fr[0] = 0;
    PQinsert(0);
    while (!PQempty()) {
        v = PQdelmin(cst);
        parnt[v] = fr[v];
        for (p=G->adj[v];p!=NULL;p=p->next){
            w = p->w;
            if (parnt[w] == -1){
                if (cst[w] == INFINITO){
                    cst[w] = p->cst;
                    fr[w] = v;
                    PQinsert(w);
                }
                else if (cst[w] > p->cst){
                    cst[w] = p->cst;
                    fr[w] = v;
                }
            }
        }
    }
}
void dijkstra(Digraph G, Vertex s){
  Vertex v, w; link p;
  for (v = 0; v < G->V; v++) {
    cst[v] = INFINITO;
    parnt[v] = -1;
  }
  PQinit(G->V);
  cst[s] = 0;
  parnt[s] = s;
  PQinsert(s);
  while (!PQempty()) {
    v = PQdelmin();
    for(p=G->adj[v];p!=NULL;p=p->next)
      if(cst[w=p->w]==INFINITO){
        cst[w]=cst[v]+p->cst;
        parnt[w]=v;
        PQinsert(w);
      }else if(cst[w]>cst[v]+p->cst){
        cst[w]=cst[v]+p->cst;
        parnt[w] = v;
        PQdec(w);
      }
  }

  PQfree();
}
Beispiel #4
0
void dijkstra(Graph G, Vertex s, Vertex parnt[], double cst[]) {
	Vertex v, w; 
	link p;

    GRAPHmaxcst(G);

	for (v = 0; v < G->V; v++) {
		cst[v] = INFINITO;
		parnt[v] = -1;
	}
	
	PQinit(G->V);
	cst[s] = 1;
	parnt[s] = s;
	PQinsert(s);
	
	while (!PQempty()) {
		v = PQdelmax(cst);
		for(p=G->adj[v];p!=NULL;p=p->next) {
			if (cst[w=p->w]==INFINITO) {
				cst[w]=cst[v]*p->cst;
				parnt[w]=v;
				PQinsert(w);
			}
			else if(cst[w]<cst[v]*p->cst) {
				cst[w]=cst[v]*p->cst;
				parnt[w] = v;
			}
		}
	}
	PQfree();
}
Beispiel #5
0
void GRAPHpfs(Graph G, int st[], double wt[])  { 
  link t; 
  int v, w;
  PQinit(); 
  priority = wt;
  for (v = 0; v < G->V; v++){ 
      st[v] = -1; 
      fr[v] = -1; 
  }
  fr[0] = 0;
  PQinsert(0);
  while (!PQempty())
    {
      v = PQdelmin(); st[v] = fr[v];
      for (t = G->adj[v]; t != NULL; t = t->next)
	if (fr[w = t->v] == -1){
	   wt[w] = P;
	   PQinsert(w); 
	   fr[w] = v;
	}
	else if ((st[w] == -1) && (P < wt[w])){
	  wt[w] = P; 
	  PQdec(w); 
	  fr[w] = v; 
	}
    }
}
Beispiel #6
0
int
shortPath (sgraph* g, snode* from, snode* to)
{
    snode* n;
    sedge* e;
    snode* adjn;
    int d;
    int   x, y;

    for (x = 0; x<g->nnodes; x++) {
	snode* temp;
	temp = &(g->nodes[x]);
	N_VAL(temp) = UNSEEN;
    }
    
    PQinit();
    if (PQ_insert (from)) return 1;
    N_DAD(from) = NULL;
    N_VAL(from) = 0;
    
    while ((n = PQremove())) {
#ifdef DEBUG
	fprintf (stderr, "process %d\n", n->index);
#endif
	N_VAL(n) *= -1;
	if (n == to) break;
	for (y=0; y<n->n_adj; y++) {
	    e = &(g->edges[n->adj_edge_list[y]]);
	    adjn = adjacentNode(g, e, n);
	    if (N_VAL(adjn) < 0) {
		d = -(N_VAL(n) + E_WT(e));
		if (N_VAL(adjn) == UNSEEN) {
#ifdef DEBUG
		    fprintf (stderr, "new %d (%d)\n", adjn->index, -d);
#endif
		    N_VAL(adjn) = d;
		    if (PQ_insert(adjn)) return 1;
		    N_DAD(adjn) = n;
		    N_EDGE(adjn) = e;
            	}
		else {
		    if (N_VAL(adjn) < d) {
#ifdef DEBUG
			fprintf (stderr, "adjust %d (%d)\n", adjn->index, -d);
#endif
			PQupdate(adjn, d);
			N_DAD(adjn) = n;
			N_EDGE(adjn) = e;
		    }
		}
	    }
	}
    }

    /* PQfree(); */
    return 0;
}
void PQsort(Item a[], int l, int r)
{
  int k;

  PQinit(r-l);
  for (k = l; k <= r; k++)
    PQinsert(a[k]);
  for (k = r; k >=l; k--)
    a[k] = PQdelmax();
}
/* triPath:
 * Find the shortest path with lengths in g from
 * v0 to v1. The returned vector (dad) encodes the
 * shorted path from v1 to v0. That path is given by
 * v1, dad[v1], dad[dad[v1]], ..., v0.
 */
static int *
triPath(tgraph * g, int n, int v0, int v1, PQ * pq)
{
    int i, j, adjn;
    double d;
    tnode *np;
    tedge *e;
    int *dad = N_NEW(n, int);

    for (i = 0; i < pq->PQsize; i++)
	N_VAL(pq, i) = UNSEEN;

    PQinit(pq);
    N_DAD(v0) = -1;
    N_VAL(pq, v0) = 0;
    PQinsert(pq, v0);

    while ((i = PQremove(pq)) != -1) {
	N_VAL(pq, i) *= -1;
	if (i == v1)
	    break;
	np = g->nodes + i;
	for (j = 0; j < np->ne; j++) {
	    e = g->edges + np->edges[j];
	    if (e->t == i)
		adjn = e->h;
	    else
		adjn = e->t;
	    if (N_VAL(pq, adjn) < 0) {
		d = -(N_VAL(pq, i) + E_WT(e));
		if (N_VAL(pq, adjn) == UNSEEN) {
		    N_VAL(pq, adjn) = d;
		    N_DAD(adjn) = i;
		    PQinsert(pq, adjn);
		} else if (N_VAL(pq, adjn) < d) {
		    PQupdate(pq, adjn, d);
		    N_DAD(adjn) = i;
		}
	    }
	}
    }
    return dad;
}