pgRouting

Changeset 136

Show
Ignore:
Timestamp:
03/23/08 12:13:02 (8 months ago)
Author:
anton
Message:

rule parsing fixed

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/core/src/shooting_star_boost_wrapper.cpp

    r124 r136  
    290290  { 
    291291    *err_msg = "Source edge not found"; 
    292     return -1
     292    return -2
    293293  } 
    294294 
     
    308308  { 
    309309    *err_msg = "Target edge not found"; 
    310     return -1
     310    return -3
    311311  } 
    312312 
     
    359359          { 
    360360            *err_msg = "Overflow"; 
    361             return -1
     361            return -4
    362362          } 
    363363      } 
     
    386386  } 
    387387 
     388  *err_msg = "Target was not reached"; 
     389  return -1; 
     390 
    388391} 
    389392 
  • trunk/core/src/shooting_star.c

    r121 r136  
    189189  int t; 
    190190 
     191  DBG("fetching\n"); 
     192 
    191193  for(t=0; t<MAX_RULE_LENGTH;++t) 
    192194    target_edge->rule[t] = -1; 
    193195     
     196  DBG("rule reset\n"); 
     197 
    194198  binval = SPI_getbinval(*tuple, *tupdesc, edge_columns->id, &isnull); 
    195199  if (isnull) 
    196200    elog(ERROR, "id contains a null value"); 
    197201  target_edge->id = DatumGetInt32(binval); 
     202  DBG("id: %i\n", target_edge->id); 
    198203   
    199204  binval = SPI_getbinval(*tuple, *tupdesc, edge_columns->source, &isnull); 
     
    201206    elog(ERROR, "source contains a null value"); 
    202207  target_edge->source = DatumGetInt32(binval); 
     208  DBG("source: %i\n", target_edge->source); 
    203209 
    204210  binval = SPI_getbinval(*tuple, *tupdesc, edge_columns->target, &isnull); 
     
    206212    elog(ERROR, "target contains a null value"); 
    207213  target_edge->target = DatumGetInt32(binval); 
     214  DBG("target: %i\n", target_edge->target); 
    208215 
    209216  binval = SPI_getbinval(*tuple, *tupdesc, edge_columns->cost, &isnull); 
     
    211218    elog(ERROR, "cost contains a null value"); 
    212219  target_edge->cost = DatumGetFloat8(binval); 
     220  DBG("cost: %f\n", target_edge->cost); 
    213221 
    214222  if (edge_columns->reverse_cost != -1)  
     
    219227        elog(ERROR, "reverse_cost contains a null value"); 
    220228      target_edge->reverse_cost =  DatumGetFloat8(binval); 
     229      DBG("r_cost: %f\n", target_edge->reverse_cost); 
     230 
    221231    } 
    222232 
     
    225235    elog(ERROR, "source x contains a null value"); 
    226236  target_edge->s_x = DatumGetFloat8(binval); 
     237  DBG("s_x: %f\n", target_edge->s_x); 
    227238 
    228239  binval = SPI_getbinval(*tuple, *tupdesc, edge_columns->s_y, &isnull); 
     
    230241    elog(ERROR, "source y contains a null value"); 
    231242  target_edge->s_y = DatumGetFloat8(binval); 
     243  DBG("s_y: %f\n", target_edge->s_y); 
    232244   
    233245  binval = SPI_getbinval(*tuple, *tupdesc, edge_columns->t_x, &isnull); 
     
    235247    elog(ERROR, "target x contains a null value"); 
    236248  target_edge->t_x = DatumGetFloat8(binval); 
     249  DBG("t_x: %f\n", target_edge->t_x); 
    237250   
    238251  binval = SPI_getbinval(*tuple, *tupdesc, edge_columns->t_y, &isnull); 
     
    240253    elog(ERROR, "target y contains a null value"); 
    241254  target_edge->t_y = DatumGetFloat8(binval); 
     255  DBG("t_y: %f\n", target_edge->t_y); 
    242256 
    243257  binval = SPI_getbinval(*tuple, *tupdesc, edge_columns->to_cost, &isnull); 
    244258  if (isnull) 
    245     target_edge->to_cost = 0; 
    246      
     259    target_edge->to_cost = 0;     
    247260  else 
    248261    target_edge->to_cost = DatumGetFloat8(binval); 
     262  DBG("to_cost: %f\n", target_edge->to_cost); 
    249263 
    250264  char *str = DatumGetCString(SPI_getvalue(*tuple, *tupdesc, edge_columns->rule)); 
    251  
    252   char* pch; 
     265   
     266  if(str != NULL) 
     267  { 
     268  char *str2 = " rule loaded\n"; 
     269  char *str3; 
     270   
     271  str3 = (char *)calloc(strlen(str) + strlen(str2) + 1, sizeof(char)); 
     272  strcat(str3, str); 
     273  strcat(str3, str2);   
     274   
     275  DBG(str3); 
     276   
     277  free(str3); 
     278 
     279  char* pch = NULL; 
    253280  int ci = MAX_RULE_LENGTH; 
    254281 
    255   pch = (char *)strtok (str," ,"); 
    256    
     282  pch = strtok (str," ,"); 
     283   
     284  DBG("parsing rule\n"); 
    257285  while (pch != NULL) 
    258286  { 
     
    261289    pch = (char *)strtok (NULL, " ,"); 
    262290  } 
    263  
     291  DBG("rule: %i\n", target_edge->rule[0]); 
     292  } 
    264293} 
    265294 
     
    329358        } 
    330359         
    331        //DBG("***%i***", ret); 
     360//     DBG("***%i***", ret); 
    332361 
    333362      ntuples = SPI_processed; 
     363      DBG("ntuples = %i", ntuples); 
     364 
    334365      total_tuples += ntuples; 
    335  
    336       if (!edges) 
     366      DBG("<%i> tuples", total_tuples); 
     367 
     368//      if (!edges) 
     369      if (total_tuples <= TUPLIMIT) 
    337370        edges = palloc(total_tuples * sizeof(edge_shooting_star_t)); 
    338371      else 
    339372        edges = repalloc(edges, total_tuples * sizeof(edge_shooting_star_t)); 
     373 
     374      DBG("memory for more %i ntuples allocated", ntuples); 
    340375 
    341376      if (edges == NULL)  
     
    349384          int t; 
    350385          SPITupleTable *tuptable = SPI_tuptable; 
     386      DBG("tuptable", ntuples); 
    351387          TupleDesc tupdesc = SPI_tuptable->tupdesc; 
     388 
     389      DBG("tupdesc", ntuples); 
    352390           
    353391          for (t = 0; t < ntuples; t++)  
    354392            { 
    355393              HeapTuple tuple = tuptable->vals[t]; 
     394      DBG("tuple", ntuples); 
    356395              fetch_edge_shooting_star(&tuple, &tupdesc, &edge_columns,  
    357396                               &edges[total_tuples - ntuples + t]); 
     397      DBG("fetch", ntuples); 
    358398            } 
    359399          SPI_freetuptable(tuptable); 
     400      DBG("freetuptable", ntuples); 
    360401        }  
    361402      else  
     
    366407     
    367408       
    368   DBG("Total %i tuples", total_tuples); 
     409  DBG("Total <%i> tuples", total_tuples); 
    369410 
    370411     
     
    419460  //time_t stime = time(NULL);     
    420461 
     462  DBG("ret =  %i\n",ret); 
     463 
    421464  ret = boost_shooting_star(edges, total_tuples, source_edge_id,  
    422465                    target_edge_id, 
     
    437480      ereport(ERROR, (errcode(ERRCODE_E_R_E_CONTAINING_SQL_NOT_PERMITTED),  
    438481        errmsg("Error computing path: %s", err_msg))); 
     482//        errmsg("Error computing path: %i", ret))); 
    439483    }  
    440484  return finish(SPIcode, ret);