Пример #1
0
static void calculate_internal_cells(NET_ALIGN *net_ali, NETWORK *net_a,NETWORK *net_b,float wwd(void *, void *, int (*cmp)(void *, void *))){    
    int a,b;

    for (a=1; a<net_ali->arcset_a.num; a++){
	for (b=1; b<net_ali->arcset_b.num; b++){ 
	    /* for (b=1; b<2; b++){ */
	    int ins_min_ind_b, del_min_ind_a, sub_min_ind_a, sub_min_ind_b;
	    float ins_min_d, del_min_d, sub_min_d;

	    if (db >= 15){
		printf("Computing minimized cost of [%d][%d]:\n",a,b);
		print_arc(net_ali->arcset_a.arcs[a],0);
		print_arc(net_ali->arcset_b.arcs[b],0);
	    }

	    calc_minimum_insert(net_ali,a,b,&ins_min_d,&ins_min_ind_b);
	    calc_minimum_delete(net_ali,a,b,&del_min_d,&del_min_ind_a);
	    calc_minimum_substi(net_ali,a,b,&sub_min_d,&sub_min_ind_a,
				&sub_min_ind_b);
	    if (db >= 15)
		printf("       Tree:     Ins = %f   Del = %f   Sub = %f\n",
		       ins_min_d, del_min_d, sub_min_d);

	    sub_min_d += wwd(net_ali->arcset_a.arcs[a]->data,
			     net_ali->arcset_b.arcs[b]->data,
			     net_a->arc_func.equal);
	    del_min_d += wwd(net_ali->arcset_a.arcs[a]->data,0,
			     net_a->arc_func.equal);
	    ins_min_d += wwd(0,net_ali->arcset_b.arcs[b]->data,
			     net_a->arc_func.equal);

	    if (db >= 15)
		printf("       Tree+wwd: Ins = %f   Del = %f   Sub = %f\n",
		       ins_min_d, del_min_d, sub_min_d);

	    if (sub_min_d <= del_min_d && sub_min_d <= ins_min_d){
		net_ali->cell[a][b].min_d  = sub_min_d;
		net_ali->cell[a][b].back_a = sub_min_ind_a;
		net_ali->cell[a][b].back_b = sub_min_ind_b;
	    } else if (del_min_d < ins_min_d) {
		net_ali->cell[a][b].min_d  = del_min_d;
		net_ali->cell[a][b].back_a = del_min_ind_a;
		net_ali->cell[a][b].back_b = b;
	    } else {
		net_ali->cell[a][b].min_d  = ins_min_d;
		net_ali->cell[a][b].back_a = a;
		net_ali->cell[a][b].back_b = ins_min_ind_b;
	    }		

	    if (db >= 15) 
		printf("       Min_d=%4.2f   back_a=%d  back_b=%d\n",
		       net_ali->cell[a][b].min_d,
		       net_ali->cell[a][b].back_a,
		       net_ali->cell[a][b].back_b);
	    
	    if (db >= 15) printf("\n");	   
	}
    }
}
Пример #2
0
void calc_minimum_substi(NET_ALIGN *net_ali,int a, int b, float *min_arc_d, int *min_ind_a, int *min_ind_b){
    int arc_a_id, arc_b_id;
    ARC *arc_a, *arc_b;
    ARC_LIST_ATOM *arcpa, *arcpb;
	    
    *min_arc_d = 999999999.9; 
    *min_ind_b = *min_ind_a = -1;
    arc_a = net_ali->arcset_a.arcs[a];
    arc_b = net_ali->arcset_b.arcs[b];

    if (db >= 15) { 
	printf("    Computing TREE SUBSITUTION Cost [%d][%d]:\n",a,b);
	printf("        ");print_arc(arc_a,0);printf("        ");
	print_arc(arc_b,0);
    }
    for (arcpa = arc_a->from_node->in_arcs; arcpa != NULL;arcpa = arcpa->next){
	if ((arc_a_id = find_arcset_id(&(net_ali->arcset_a),arcpa->arc,a)) <0){
	    fprintf(stderr,"Error: netA find_arcset_id failed\n");
	    exit(1);
	}
	for (arcpb = arc_b->from_node->in_arcs; arcpb != NULL;
	     arcpb = arcpb->next){
	    if ((arc_b_id = find_arcset_id(&(net_ali->arcset_b),
					   arcpb->arc,b)) <0){
		fprintf(stderr,"Error: netB find_arcset_id failed\n");
		exit(1);
	    }
	    if (db >= 15) {printf("       look back to cell: %d,%d\n",
				  arc_a_id, arc_b_id); 
			   printf("          ");print_arc(arcpa->arc,0);
			   printf("          ");print_arc(arcpb->arc,0);}
	    if (net_ali->cell[arc_a_id][arc_b_id].min_d < *min_arc_d){
		*min_arc_d = net_ali->cell[arc_a_id][arc_b_id].min_d;
		*min_ind_b = arc_b_id;
		*min_ind_a = arc_a_id;
	    }
	}
    }
    if (db >= 15) 
	printf("         Min_d=%4.2f   cell [%d][%d]\n\n",
	       *min_arc_d, *min_ind_a, *min_ind_b);
}
Пример #3
0
void dump_NET_ALIGN(NET_ALIGN *net_ali,FILE *fp){
    int aa, bb;
    printf("Dump of net_ali:\n");
    
    printf("\nArc List from Network A\n");
    for (aa=0; aa<net_ali->arcset_a.num; aa++){
	printf("  %2d: ",aa);
	print_arc(net_ali->arcset_a.arcs[aa],0);
    }
      
    printf("\nArc List from Network B\n");
    for (bb=0; bb<net_ali->arcset_b.num; bb++){
	printf("  %2d: ",bb);
	print_arc(net_ali->arcset_b.arcs[bb],0);
    }
    
    printf("\n       ");
    for (bb=0; bb<net_ali->arcset_b.num; bb++)
	printf("   %3d   ",bb);
    printf("\n");
    for (aa=0; aa<net_ali->arcset_a.num; aa++) {
	printf("  %3d  ",aa);
	for (bb=0; bb<net_ali->arcset_b.num; bb++)
	    printf("D%6.3f  ",net_ali->cell[aa][bb].min_d);
	printf("\n");
	printf("       ");
	for (bb=0; bb<net_ali->arcset_b.num; bb++){
	    if (aa == net_ali->cell[aa][bb].back_a)
		printf("I=");
	    else if (bb == net_ali->cell[aa][bb].back_b)
		printf("D=");
	    else
		printf("S=");
	    printf("%2d,%2d  ",net_ali->cell[aa][bb].back_a,
		   net_ali->cell[aa][bb].back_b);
	}
	printf("\n\n");
    }
}
Пример #4
0
void calc_minimum_delete(NET_ALIGN *net_ali,int a, int b, float *min_arc_d, int *min_ind_a){
    int arc_a_id;
    ARC *arc_b, *arc_a;
    ARC_LIST_ATOM *arcpa;

    *min_arc_d = 999999999.9;
    *min_ind_a = -1;
    arc_a = net_ali->arcset_a.arcs[a];
    arc_b = net_ali->arcset_b.arcs[b];
    if (db >= 15) {
	printf("    Computing TREE DELETE COST [%d][%d]:\n",a,b);
	printf("        ");
	print_arc(arc_a,0);
	printf("        ");
	print_arc(arc_b,0);
    }

    for (arcpa = arc_a->from_node->in_arcs; arcpa != NULL;arcpa = arcpa->next){
	if ((arc_a_id = find_arcset_id(&(net_ali->arcset_a),arcpa->arc,a)) <0){
	    fprintf(stderr,"Error: find_arcset_id failed in\n");
	    exit(1);
	}
	if (db >= 15) {printf("       look back to cell: %d,%d\n",arc_a_id, b); 
		       printf("           ");
		       print_arc(arcpa->arc,0);
		       printf("           ");
		       print_arc(arc_b,0);}
	if (net_ali->cell[arc_a_id][b].min_d < *min_arc_d){
	    *min_arc_d = net_ali->cell[arc_a_id][b].min_d;
	    *min_ind_a = arc_a_id;
	}
    }
    if (db >= 15) 
	printf("         Min_d=%4.2f   cell [%d][%d]\n",
	       *min_arc_d, *min_ind_a, b);
}
Пример #5
0
/* generator of layered networks for the shortest paths problem;
   extended DIMACS format for output */
int
gen_spgrid_topology (struct vty *vty, struct list *topology)
{
  /* ----- ajusting parameters ----- */

  /* spanning */
  if ( cl < cm ) { lx = cl; cl = cm; cm = lx; }

  /* additional arcs */
  if ( al < am ) { lx = al; al = am; am = lx; }

  /* interlayered arcs */
  if ( il < im ) { lx = il; il = im; im = lx; }

  /* potential parameters */
  if ( p_f )
    {
     if ( ! pl_f ) pl = il;
     if ( ! pm_f ) pm = im;
     if ( pl < pm ) { lx = pl; pl = pm; pm = lx; }
    }

  /* number of nodes and arcs */

  n = (double)X *(double)Y + 1;

  m  = (double)Y; /* arcs from source */

  switch ( cw )
  {
   case PATH:
    mc = (double)Y - 1;
    break;
   case CYCLE:
    mc = (double)Y;
    break;
   case DOUBLE_CYCLE:
    mc = 2*(double)Y;
  }

  m += (double)X * (double)mc;  /* spanning arcs */
  m += (double)X * (double)ax;  /* additional arcs */

  /* interlayered arcs */
  for ( x = 0; x < X; x ++ )
  {
    dl = ( ( X - x - 1 ) + ( ih - 1 ) ) / ih;
    if ( dl > ix ) dl = ix;
    m += (double)Y * (double)dl;
  }

   /* artifical source parameters */
  if ( s_f ) {
    m += n; n ++ ;
    if ( ! sm_f ) sm = sl;
    if ( sl < sm ) { lx = sl; sl = sm; sm = lx; }
  }

  if ( n >= (double)LONG_MAX || m >= (double)LONG_MAX )
  {
    zlog_err ("Too large problem. It can't be generated\n");
    exit (4);
  }
   else
  {
    n0 = (long)n; m0 = (long)m;
  }

  if ( ip_f )
     mess = (long*) calloc ( Y, sizeof ( long ) );

  /* printing title */
  zlog_info ("Generating topology for ISIS");

  source = ( s_f ) ? n0-1 : n0;

  if ( p_f ) /* generating potentials */ {
    p = (long*) calloc ( n0+1, sizeof (long) );
    seed1 = 2*seed + 1;
    init_rand ( seed1);
    pl = pl - pm + 1;

    for ( x = 0; x < X; x ++ )
      for ( y = 0; y < Y; y ++ ) {
        p_t = pm + nrand ( pl );
        if ( pn_f ) p_t *= (long) ( (1 + x) * pn );
        if ( ps_f ) p_t *= (long) ( (1 + x) * ( (1 + x) * ps ));

        p[ NODE ( x, y ) ] = p_t;
      }
      p[n0] = 0;
      if ( s_f ) p[n0-1] = 0;
    }

  if ( s_f ) /* additional arcs from artifical source */
    {
      seed2 = 3*seed + 1;
      init_rand ( seed2 );
      sl = sl - sm + 1;

      for ( x = X - 1; x >= 0; x -- )
        for ( y = Y - 1; y >= 0; y -- )
        {
          i = NODE ( x, y );
          s = sm + nrand ( sl );
          print_arc (vty, topology,  n0, i, s );
        }

      print_arc (vty, topology,  n0, n0-1, 0 );
    }


  /* ----- generating arcs within layers ----- */

  init_rand ( seed );
  cl = cl - cm + 1;
  al = al - am + 1;

  for ( x = 0; x < X; x ++ )
   {
  /* generating arcs within one layer */
    for ( y = 0; y < Y-1; y ++ )
    {
       /* generating spanning graph */
       i = NODE ( x, y );
       j = NODE ( x, y+1 );
       l = cm + nrand ( cl );
       print_arc (vty, topology,  i, j, l );

       if ( cw == DOUBLE_CYCLE )
         {
           l = cm + nrand ( cl );
           print_arc (vty, topology,  j, i, l );
         }
     }

    if ( cw <= CYCLE )
      {
        i = NODE ( x, Y-1 );
        j = NODE ( x, 0 );
        l = cm + nrand ( cl );
        print_arc (vty, topology,  i, j, l );

        if ( cw == DOUBLE_CYCLE )
          {
  	  l = cm + nrand ( cl );
            print_arc (vty, topology,  j, i, l );
          }
       }

  /* generating additional arcs */

    for ( k = ax; k > 0; k -- )
       {
         yy1 = nrand ( Y );
         do
            yy2 = nrand ( Y );
         while ( yy2 == yy1 );
         i  = NODE ( x, yy1 );
         j  = NODE ( x, yy2 );
         l = am + nrand ( al );
         print_arc (vty, topology,  i, j, l );
       }
   }

  /* ----- generating interlayered arcs ------ */

  il = il - im + 1;

  /* arcs from the source */

    for ( y = 0; y < Y; y ++ )
      {
        l = im + nrand ( il );
        i = NODE ( 0, y );
        print_arc (vty, topology,  source, i, l );
      }

  for ( x = 0; x < X-1; x ++ )
   {
  /* generating arcs from one layer */
     for ( count = 0, xn = x + 1;
           count < ix && xn < X;
           count ++, xn += ih )
      {
        if ( ip_f )
        for ( y = 0; y < Y; y ++ )
  	mess[y] = y;

        for ( y = 0; y < Y; y ++ )
         {
            i = NODE ( x, y );
  	  dx = xn - x;
  	  if ( ip_f )
  	    {
  	      yyp = nrand(Y-y);
  	      yyn = mess[ yyp ];
                mess[ yyp ] = mess[ Y - y - 1 ];
  	    }
  	  else
               yyn =  y;
  	  j = NODE ( xn, yyn );
  	  l = im + nrand ( il );
  	  if ( in != 0 )
              l *= (long) ( in * dx );
            if ( is_f )
              l *= (long) ( ( is * dx ) * dx );
            print_arc (vty, topology,  i, j, l );
  	}
      }
   }
  /* all is done */
  return ext;

return 0;
}
Пример #6
0
void find_minimal_paths(NET_ALIGN *net_ali, int a, int b, int *rlev,float wwd(void *, void *, int (*cmp)(void *, void *)),NETWORK *net_a, PATH *path,int *count)
{

    ARC_LIST_ATOM *oarc_a, *oarc_b;
    ARC *arc_a, *arc_b;
    int la, lb, cost;
    int arc_a_id, arc_b_id,d;
    int db = 0;
    char buf[100];

    sprintf(buf,rsprintf("%%0%ds",*rlev),"");
    if (a == 0 && b == 0){
	if (db > 5) printf("END recursion\n");
	if (db > 2) {
	    printf("Count = %d\n",*count);
	    PATH_print(path,stdout,100);
	}
	(*count)++;
	return;
    }

    arc_a = net_ali->arcset_a.arcs[a];
    arc_b = net_ali->arcset_b.arcs[b];
    cost  = net_ali->cell[a][b].min_d;

    if (db > 5){
	printf("%sCurrent position: D(%d,%d) = %d\n",buf,a,b,cost);
	printf("%s    ",buf); print_arc(arc_a,0);
	printf("%s    ",buf); print_arc(arc_b,0);
    }

    /* loop through the net A in_arcs, seaching for possible paths */
    for (oarc_a = arc_a->from_node->in_arcs; oarc_a != NULL;
	 oarc_a=oarc_a->next){
	if ((arc_a_id = find_arcset_id(&(net_ali->arcset_a),oarc_a->arc,
				       a)) <0){
	    fprintf(stderr,"Error: find_arcset_id for Net A failed\n");
	    exit(1);
	}
	if (db > 5) {
	    printf("%s    Checking deletion arcs:\n",buf);
	    printf("%s        A:",buf); print_arc(oarc_a->arc,0);
	}
	if (net_ali->cell[arc_a_id][b].min_d <= cost && 
	    (wwd(arc_a->data,NULL_WORD,net_a->arc_func.equal) +
	     net_ali->cell[arc_a_id][b].min_d) <= cost){
	    if (db > 5) printf("%s            Possible PATH\n",buf);
	    if (db > 5) printf("%s            *****  Delete %s\n",buf,
			       ((WORD*)(arc_b->data))->value);
	    *rlev += 2;
	    PATH_append(path,arc_a->data,0,P_DEL);
	    find_minimal_paths(net_ali,arc_a_id,b,rlev,wwd,net_a,path,count);
	    PATH_remove(path);
	    *rlev -= 2;
	}
    }
    for (oarc_b = arc_b->from_node->in_arcs; oarc_b != NULL;
	 oarc_b = oarc_b->next){
	if ((arc_b_id = find_arcset_id(&(net_ali->arcset_b),oarc_b->arc,
				       b)) < 0){
	    fprintf(stderr,"Error: find_arcset_id for Net B failed\n");
	    exit(1);
	}
	if (db > 5) {
	    printf("%s    Checking insertion arcs:\n",buf);
	    printf("%s        B:",buf); print_arc(oarc_b->arc,0);
	}
	if (net_ali->cell[a][arc_b_id].min_d <= cost &&
	    (wwd(NULL_WORD,arc_b->data,net_a->arc_func.equal) +
	     net_ali->cell[a][arc_b_id].min_d) <= cost){
	    if (db > 5) printf("%s            Possible PATH\n",buf);
	    if (db > 5) printf("%s            *****  Insert %s\n",buf,
			       ((WORD*)(arc_b->data))->value);
	    *rlev += 2;
	    PATH_append(path,0,arc_b->data,P_INS);
	    find_minimal_paths(net_ali,a,arc_b_id,rlev,wwd,net_a,path,count);
	    PATH_remove(path);
	    *rlev -= 2;
	}
    }


    for (oarc_a = arc_a->from_node->in_arcs; oarc_a != NULL;
	 oarc_a=oarc_a->next){
	if ((arc_a_id = find_arcset_id(&(net_ali->arcset_a),oarc_a->arc,
				       a)) <0){
	    fprintf(stderr,"Error: find_arcset_id for Net A failed\n");
	    exit(1);
	}
	for (oarc_b = arc_b->from_node->in_arcs; oarc_b != NULL;
	     oarc_b = oarc_b->next){
	    if ((arc_b_id = find_arcset_id(&(net_ali->arcset_b),oarc_b->arc,
					   b)) < 0){
		fprintf(stderr,"Error: find_arcset_id for Net B failed\n");
		exit(1);
	    }
	    if (db > 5) {
		printf("%s    Checking substitution arcs: (%d,%d)\n",buf,
		       arc_a_id,arc_b_id);
		printf("%s        A:",buf); print_arc(oarc_a->arc,0);
		printf("%s        B:",buf); print_arc(oarc_b->arc,0);
	    }
	    if (net_ali->cell[arc_a_id][arc_b_id].min_d <= cost &&
		((d=wwd(arc_a->data,arc_b->data,net_a->arc_func.equal)) + 
		 net_ali->cell[arc_a_id][arc_b_id].min_d) <= cost){
		if (db > 5){ 
		    printf("%s            Possible PATH\n",buf);
		    printf("%s            *****  Substitute %s and %s\n",buf,
			   ((WORD*)(arc_a->data))->value,
			   ((WORD*)(arc_b->data))->value);
		}
		*rlev += 2;
		PATH_append(path,arc_a->data,arc_b->data,(d==0)?P_CORR:P_SUB);
		find_minimal_paths(net_ali,arc_a_id,arc_b_id,rlev,wwd,net_a,path,count);
		PATH_remove(path);
		*rlev -= 2;
	    }
	}	
    }
    la = a;	lb = b;
    a = net_ali->cell[la][lb].back_a;
    b = net_ali->cell[la][lb].back_b;
}
Пример #7
0
void create_alinged_NETWORK(NET_ALIGN *net_ali, NETWORK *net_a, NETWORK *net_b, void *null_alt, int iteration){
    char *proc = "create_alinged_NETWORK";
    ARC_LIST_ATOM *arcpa, *arcpb;
    void *copy_b_arc_data;
    int min_a, min_b;
    int a, b, i;
    int arc_a_id, arc_b_id;
    float min_arc_d;
    int new_db = 0;


    if (getenv("ALIGN_NET_DBL") != NULL) 
        new_db=(int)atof(getenv("ALIGN_NET_DBL"));

    if (new_db >= 10) printf("Entering %s:\n",proc);
    
    /* Find the minimal network termination node, */
    /* !!!!  It's not just max x,y any more   !!!!*/
    min_arc_d = 999999.9;
    a = b = -1;
    for (arcpa = net_a->stop_node->in_arcs; arcpa != NULL;arcpa =arcpa->next){
	if ((arc_a_id = find_arcset_id(&(net_ali->arcset_a),arcpa->arc,
				       net_ali->arcset_a.num)) <0){
	    fprintf(stderr,"Error: find_arcset_id for Net A failed\n");
	    exit(1);
	}
	for (arcpb = net_b->stop_node->in_arcs; arcpb != NULL;
	     arcpb = arcpb->next){
	    if ((arc_b_id = find_arcset_id(&(net_ali->arcset_b),arcpb->arc,
					   net_ali->arcset_b.num)) < 0){

		fprintf(stderr,"Error: find_arcset_id for Net B failed\n");
		exit(1);
	    }
	    if (min_arc_d > net_ali->cell[arc_a_id][arc_b_id].min_d){
		min_arc_d = net_ali->cell[arc_a_id][arc_b_id].min_d;
		a = arc_a_id; b = arc_b_id;
	    }
	}
    }
    min_a = a;
    min_b = b;

    /*******************************************************************/
    /*     Beginning the Back Trace copying the B-arcs onto A_net      */

    if (new_db >= 10)
        printf("Minimal Start point: D(%d,%d) = %f\n",min_a,min_b,min_arc_d);

    a = min_a ; b = min_b;
    while (a > 0 || b > 0){
	int la = a, lb = b;
	ARC *a_arc, *b_arc;
	enum edits back;

	back = (a == net_ali->cell[a][b].back_a) ? INS : 
	            ((b == net_ali->cell[a][b].back_b) ? DEL : SUB);
	b_arc = net_ali->arcset_b.arcs[b];
	a_arc = net_ali->arcset_a.arcs[a];

	switch (back){
	  case SUB:
 	    /* insert a copy the B_arc onto the from_node and to_node of the 
	       A_arc */
	    if (new_db >= 10){
	        printf("%s: SUB\n",proc);
		printf("%s:   Insert copy of B_arc",proc);
		print_arc(b_arc,stdout);
		printf("%s:   between A_arcs(from)",proc);
		print_node(a_arc->from_node,stdout);
		printf("%s:           A_arcs(to)  ",proc);
		print_node(a_arc->to_node,stdout);
	    }
	    if (NETWORK_insert_arc_between_node(net_a, a_arc->from_node,
						a_arc->to_node,
				    b_arc->net->arc_func.copy(b_arc->data)) != 0)
	        goto ERROR;

	    break;
	  case DEL:
	    /* insert a @ arc onto the from_node and to_node of the A_arc */
	    if (new_db >= 10){
	        printf("%s: DEL\n",proc);
		printf("%s:   Insert copy of null_alt\n",proc);
		printf("%s:   between A_arcs(from)",proc);
		print_node(a_arc->from_node,stdout);
		printf("%s:           A_arcs(to)  ",proc);
		print_node(a_arc->to_node,stdout);
	    }
	    if (NETWORK_insert_arc_between_node(net_a, a_arc->from_node,
				    a_arc->to_node,
 				    a_arc->net->arc_func.copy(null_alt)) != 0)
	        goto ERROR;

	    break;
  	  case INS:
	    /* insert a subnetwork of { @ / B_arc } onto the from_node    */
	    /* and to_node of the A_arc,  There will be 'iteration' @'s   */
	    /* inside this network */

	    if (new_db >= 10){
	        printf("%s: INS\n",proc);
		printf("%s:   Insert a subnet with %d null arcs and a "
		       "copy of b_arc\n",proc,iteration);
		printf("%s:  Insert copy of B_arc",proc);
		print_arc(b_arc,stdout);
		printf("%s:  At A_arcs(to_node)  ",proc);
		print_node(a_arc->to_node,stdout);
	    }
	    /* first, insert the copy of b_arc's data into the A_net */
	    copy_b_arc_data = a_arc->net->arc_func.copy(b_arc->data);
	    if (NETWORK_insert_arc_before_node(a_arc->net,
					       a_arc->to_node,
					       copy_b_arc_data) != 0)
	        goto ERROR;
	    /* Find, in A_net, the new arc */
	    for (arcpa = a_arc->to_node->out_arcs; arcpa != NULL;
		 arcpa = arcpa->next)
	        if (arcpa->arc->data == copy_b_arc_data){
		    break;
		}
	    if (arcpa == NULL){
	        fprintf(scfp,"Internal Error\n");
		goto ERROR;
	    }
	    for (i=0; i<iteration; i++)
	      if (NETWORK_insert_arc_between_node(arcpa->arc->net,
						  arcpa->arc->from_node,
						  arcpa->arc->to_node,
				       a_arc->net->arc_func.copy(null_alt)) != 0)
	        goto ERROR;
	    break;
	}
	la = a;	                           lb = b;
	a = net_ali->cell[la][lb].back_a;  b = net_ali->cell[la][lb].back_b;
    }
    goto CLEANUP;

  ERROR:
    printf("ERROR OCCURED\n");
  CLEANUP:
    return;
}
Пример #8
0
PATH *extract_NET_ALIGN_result(NET_ALIGN *net_ali,NETWORK *net_a,NETWORK *net_b, int include_nulls){
    PATH *t_path;
    ARC_LIST_ATOM *arcpa, *arcpb;
    int back_path, min_a, min_b, hops;
    int a, b;
    int arc_a_id, arc_b_id;
    float min_arc_d;

    /*********************************/
    /*     Beginning Back Trace      */

    /* Find the minimal network termination node, */
    /* !!!!  It's not just max x,y any more   !!!!*/
    min_arc_d = 999999.9;
    a = b = -1;
    for (arcpa = net_a->stop_node->in_arcs; arcpa != NULL;arcpa =arcpa->next){
	if ((arc_a_id = find_arcset_id(&(net_ali->arcset_a),arcpa->arc,
				       net_ali->arcset_a.num)) <0){
	    fprintf(stderr,"Error: find_arcset_id for Net A failed\n");
	    exit(1);
	}
	for (arcpb = net_b->stop_node->in_arcs; arcpb != NULL;
	     arcpb = arcpb->next){
	    if ((arc_b_id = find_arcset_id(&(net_ali->arcset_b),arcpb->arc,
					   net_ali->arcset_b.num)) < 0){

		fprintf(stderr,"Error: find_arcset_id for Net B failed\n");
		exit(1);
	    }
	    if (min_arc_d > net_ali->cell[arc_a_id][arc_b_id].min_d){
		min_arc_d = net_ali->cell[arc_a_id][arc_b_id].min_d;
		a = arc_a_id; b = arc_b_id;
	    }
	}
    }
    min_a = a;
    min_b = b;

    {if (getenv("DBL") != NULL) { db=(int)atof(getenv("DBL")); }}

    if (db >= 25) dump_NET_ALIGN(net_ali,stdout);

    /* first do a back trace, counting the hops */
    a = min_a ; b = min_b; hops = 0;
    while (a > 0 || b > 0){
	int la, lb;
	if (db >= 15)
	    printf("Counting hops  a=%d b=%d   %d,%d\n",a,b,
		   net_ali->cell[a][b].back_b,net_ali->cell[a][b].back_a);

	hops ++;
	/* check for an insertion of "@", and ignore it */
	if (b == net_ali->cell[a][b].back_b) {
	    if (!include_nulls &&
		net_a->arc_func.is_null_alt(net_ali->arcset_a.arcs[a]->data)){
		if (db >= 15) printf("Insertion of nulls\n");
		hops --;
	    }
	} else if (a == net_ali->cell[a][b].back_a) {
	    /* check for a deletion of "@", and ignore it */
	    if (!include_nulls &&
		net_b->arc_func.is_null_alt(net_ali->arcset_b.arcs[b]->data)){
		if (db >= 15) printf("deletion of null\n");
		hops --;
	    }
	} else {
	    /* check for a substitution of "@", and ignore it */
	    if (!include_nulls &&
		(net_a->arc_func.is_null_alt(net_ali->arcset_a.arcs[a]->data))&&
		(net_b->arc_func.is_null_alt(net_ali->arcset_b.arcs[b]->data))){
		printf("substition of to nulls\n");
		hops --;
	    }
	}
	la = a;	lb = b;
	a = net_ali->cell[la][lb].back_a;
	b = net_ali->cell[la][lb].back_b;
    }
    a = min_a ; b = min_b;
    if (db >= 10)
	printf("Minimal Start point: D(%d,%d) = %f  hops(%d)\n",
	       a,b,min_arc_d,hops);
    
    t_path = PATH_alloc(hops);
    back_path = hops - 1;

    a = min_a ; b = min_b;
    while (a > 0 || b > 0){
	int la, lb;
	enum edits back;
	back = (a == net_ali->cell[a][b].back_a) ? INS : 
	            ((b == net_ali->cell[a][b].back_b) ? DEL : SUB);
	switch (back){
	  case DEL:
	    if (include_nulls ||
		!net_a->arc_func.is_null_alt(net_ali->arcset_a.arcs[a]->data)){
	      if (! net_a->arc_func.is_opt_del(net_ali->arcset_a.arcs[a]->data)){
		t_path->pset[back_path].a_ptr = net_ali->arcset_a.arcs[a]->data;
		net_a->arc_func.use_count(net_ali->arcset_a.arcs[a]->data,1);
		t_path->pset[back_path].b_ptr = (void *)0;
		if (db >= 15){
		  printf("Del  %d %d  \n",a,b);
		  print_arc(net_ali->arcset_a.arcs[a],0);
		  printf("     *\n");
		}
		t_path->pset[back_path].eval = P_DEL;
	      } else { 
		/**** OPTIONALLY deletable, make it correct */
		t_path->pset[back_path].a_ptr = net_ali->arcset_a.arcs[a]->data;
		net_a->arc_func.use_count(net_ali->arcset_a.arcs[a]->data,1);
		t_path->pset[back_path].b_ptr = 
		  net_a->arc_func.make_empty((void*)0);
		if (db >= 15){
		  printf("Corr Del  %d %d  \n",a,b);
		  print_arc(net_ali->arcset_a.arcs[a],0);
		}
		t_path->pset[back_path].eval = P_CORR;
	      }
	      
	      --back_path; 	t_path->num ++;
	    }
	    break;
	  case SUB:
	    if(include_nulls ||
	       !(net_b->arc_func.is_null_alt(net_ali->arcset_a.arcs[a]->data)&&
		 net_b->arc_func.is_null_alt(net_ali->arcset_b.arcs[b]->data))){
		t_path->pset[back_path].a_ptr = net_ali->arcset_a.arcs[a]->data;
		net_a->arc_func.use_count(net_ali->arcset_a.arcs[a]->data,1);
		t_path->pset[back_path].b_ptr = net_ali->arcset_b.arcs[b]->data;
		net_a->arc_func.use_count(net_ali->arcset_b.arcs[b]->data,1);
		if (db >= 15){	
		    printf("Sub  %d %d  \n",a,b);
		    print_arc(net_ali->arcset_a.arcs[a],0);
		    print_arc(net_ali->arcset_b.arcs[b],0);
		}
		if (net_a->arc_func.equal(t_path->pset[back_path].a_ptr,
					  t_path->pset[back_path].b_ptr) == 0)
		    t_path->pset[back_path].eval = P_CORR;
		else
		    t_path->pset[back_path].eval = P_SUB;
		--back_path; 	t_path->num ++;
	    }
	    break;
	  case INS:
	    if (include_nulls  ||
		!net_b->arc_func.is_null_alt(net_ali->arcset_b.arcs[b]->data)){
	      if (! net_b->arc_func.is_opt_del(net_ali->arcset_b.arcs[b]->data)){
		t_path->pset[back_path].a_ptr = (void *)0;
		t_path->pset[back_path].b_ptr = net_ali->arcset_b.arcs[b]->data;
		net_a->arc_func.use_count(net_ali->arcset_b.arcs[b]->data,1);
	    
		if (db >= 15){
		    printf("INS  %d %d \n",a,b);
		    printf("     *\n");
		    print_arc(net_ali->arcset_b.arcs[b],0);
		}
		t_path->pset[back_path].eval = P_INS;
	      } else {
		t_path->pset[back_path].a_ptr = 
		  net_b->arc_func.make_empty((void*)0);
		t_path->pset[back_path].b_ptr = net_ali->arcset_b.arcs[b]->data;
		net_a->arc_func.use_count(net_ali->arcset_b.arcs[b]->data,1);
	    
		if (db >= 15){
		    printf("CORR INS  %d %d \n",a,b);
		    printf("     *\n");
		    print_arc(net_ali->arcset_b.arcs[b],0);
		}
		t_path->pset[back_path].eval = P_CORR;
	      }
		--back_path; 	t_path->num ++;
	    }
	}
	la = a;
	lb = b;
	a = net_ali->cell[la][lb].back_a;
	b = net_ali->cell[la][lb].back_b;
    }
    return(t_path);
}