Graph MakeGraph(int numvert, int numproc) { int perproc = numvert/numproc; int i,j; int count1; Vertex v,tmp; Vertex block; Graph retval; #ifdef FUTURES future_cell_int fc[MAXPROC]; #endif retval = (Graph) ALLOC(0,sizeof(*retval)); for (i=0; i<MAXPROC; i++) { retval->vlist[i]=NULL; } chatting("Make phase 2\n"); for (j=numproc-1; j>=0; j--) { block = (Vertex) ALLOC(j,perproc*(sizeof(*tmp))); v = NULL; for (i=0; i<perproc; i++) { tmp = block+(perproc-i-1); HashRange = numvert/4; tmp->mindist = 9999999; tmp->edgehash = MakeHash(numvert/4,hashfunc); tmp->next = v; v=tmp; } retval->vlist[j] = v; } chatting("Make phase 3\n"); for (j=numproc-1; j>=0; j--) { count1 = j*perproc; #ifndef FUTURES AddEdges(count1, retval, numproc, perproc, numvert, j); #else FUTURE(count1,retval,numproc,perproc,numvert,j,AddEdges,&fc[j]); #endif } /* for j... */ chatting("Make phase 4\n"); #ifdef FUTURES for (j=0; j<numproc; j++) { TOUCH(&fc[j]); } #endif chatting("Make returning\n"); return retval; }
/* * Generates random connected undirected graphs. Unfortunately this current * implementation does not generate the graphs with a uniform distribution. * * Apparently a good reference is Tinhofer G., , * C. Hanser, Verlag, M\"{u}nchen 1980. */ Vertices * GenGraph(int nVertex, int nEdge) { Vertices * graph; assert(nEdge + 1 >= nVertex); assert(nEdge <= nVertex * (nVertex - 1) / 2); generatedEdges = 0; graph = GenTree(nVertex); graph = AddEdges(graph, nVertex, nEdge - nVertex + 1); return(graph); }
static void FindGlobalEdges(EdgeList &Edges, int MaxImageCount) { Edges.clear(); PILE_INDEX_TYPE *Partners = all(PILE_INDEX_TYPE, MaxImageCount); bool *PartnersRev = all(bool, MaxImageCount); for (int PileIndex = 0; PileIndex < PileCount; ++PileIndex) { PileData &Pile = Piles[PileIndex]; int PartnerCount; if (g_paramSingleHitCoverage) PartnerCount = FindGlobalEdgesPileSingle(Pile, PileIndex, Partners, PartnersRev); else PartnerCount = FindGlobalEdgesPileMulti(Pile, PileIndex, Partners, PartnersRev); AddEdges(Edges, PileIndex, Partners, PartnersRev, PartnerCount); } freemem(Partners); freemem(PartnersRev); }
void ContestDijkstra::AddIncrementalEdges(unsigned first_point) { assert(first_point < n_points); assert(continuous); assert(incremental); assert(finished); finished = false; first_finish_candidate = first_point; /* we need a copy of the current edge map, because the following loop will modify it, invalidating the iterator */ #if GCC_VERSION < 40800 || GCC_VERSION > 40802 const Dijkstra::EdgeMap edges = dijkstra.GetEdgeMap(); #else // workaround for http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59548 Dijkstra::EdgeMap edges; edges = dijkstra.GetEdgeMap(); #endif /* establish links between each old node and each new node, to initiate the follow-up search, hoping a better solution will be found here */ for (const auto &i : edges) { if (IsFinal(i.first)) /* ignore final nodes */ continue; /* "seek" the Dijkstra object to the current "old" node */ dijkstra.SetCurrentValue(i.second.value); /* add edges from the current "old" node to all "new" nodes (first_point .. n_points-1) */ AddEdges(i.first, first_point); } /* see if new start points are possible now (due to relaxed start height constraints); duplicates will be ignored by the Dijkstra class */ AddStartEdges(); }
Graph MakeGraph(int numvert, int numproc) { int perproc = numvert/numproc; int i,j; int count1; Vertex v,tmp; Vertex block; Graph retval; retval = (Graph)malloc(sizeof(*retval)); for (i=0; i<MAXPROC; i++) { retval->vlist[i]=NULL; } chatting("Make phase 2\n"); for (j=numproc-1; j>=0; j--) { block = (Vertex) malloc(perproc*(sizeof(*tmp))); v = NULL; for (i=0; i<perproc; i++) { tmp = block+(perproc-i-1); HashRange = numvert/4; tmp->mindist = 9999999; tmp->edgehash = MakeHash(numvert/4,hashfunc); tmp->next = v; v=tmp; } retval->vlist[j] = v; } chatting("Make phase 3\n"); for (j=numproc-1; j>=0; j--) { count1 = j*perproc; AddEdges(count1, retval, numproc, perproc, numvert, j); } /* for j... */ chatting("Make phase 4\n"); chatting("Make returning\n"); return retval; }
void ContestDijkstra::AddIncrementalEdges(unsigned first_point) { assert(first_point < n_points); assert(continuous); assert(incremental); assert(finished); finished = false; first_finish_candidate = first_point; /* we need a copy of the current edge map, because the following loop will modify it, invalidating the iterator */ const Dijkstra::EdgeMap edges = dijkstra.GetEdgeMap(); /* establish links between each old node and each new node, to initiate the follow-up search, hoping a better solution will be found here */ for (auto i = edges.begin(), end = edges.end(); i != end; ++i) { if (IsFinal(i->first)) /* ignore final nodes */ continue; /* "seek" the Dijkstra object to the current "old" node */ dijkstra.SetCurrentValue(i->second.value); /* add edges from the current "old" node to all "new" nodes (first_point .. n_points-1) */ AddEdges(i->first, first_point); } /* see if new start points are possible now (due to relaxed start height constraints); duplicates will be ignored by the Dijkstra class */ AddStartEdges(); }
CPLErr CPL_STDCALL GDALFPolygonize( GDALRasterBandH hSrcBand, GDALRasterBandH hMaskBand, OGRLayerH hOutLayer, int iPixValField, char **papszOptions, GDALProgressFunc pfnProgress, void * pProgressArg ) { #ifndef OGR_ENABLED CPLError(CE_Failure, CPLE_NotSupported, "GDALFPolygonize() unimplemented in a non OGR build"); return CE_Failure; #else VALIDATE_POINTER1( hSrcBand, "GDALFPolygonize", CE_Failure ); VALIDATE_POINTER1( hOutLayer, "GDALFPolygonize", CE_Failure ); if( pfnProgress == NULL ) pfnProgress = GDALDummyProgress; int nConnectedness = CSLFetchNameValue( papszOptions, "8CONNECTED" ) ? 8 : 4; /* -------------------------------------------------------------------- */ /* Confirm our output layer will support feature creation. */ /* -------------------------------------------------------------------- */ if( !OGR_L_TestCapability( hOutLayer, OLCSequentialWrite ) ) { CPLError( CE_Failure, CPLE_AppDefined, "Output feature layer does not appear to support creation\n" "of features in GDALFPolygonize()." ); return CE_Failure; } /* -------------------------------------------------------------------- */ /* Allocate working buffers. */ /* -------------------------------------------------------------------- */ CPLErr eErr = CE_None; int nXSize = GDALGetRasterBandXSize( hSrcBand ); int nYSize = GDALGetRasterBandYSize( hSrcBand ); float *pafLastLineVal = (float *) VSIMalloc2(sizeof(float),nXSize + 2); float *pafThisLineVal = (float *) VSIMalloc2(sizeof(float),nXSize + 2); GInt32 *panLastLineId = (GInt32 *) VSIMalloc2(sizeof(GInt32),nXSize + 2); GInt32 *panThisLineId = (GInt32 *) VSIMalloc2(sizeof(GInt32),nXSize + 2); GByte *pabyMaskLine = (hMaskBand != NULL) ? (GByte *) VSIMalloc(nXSize) : NULL; if (pafLastLineVal == NULL || pafThisLineVal == NULL || panLastLineId == NULL || panThisLineId == NULL || (hMaskBand != NULL && pabyMaskLine == NULL)) { CPLError(CE_Failure, CPLE_OutOfMemory, "Could not allocate enough memory for temporary buffers"); CPLFree( panThisLineId ); CPLFree( panLastLineId ); CPLFree( pafThisLineVal ); CPLFree( pafLastLineVal ); CPLFree( pabyMaskLine ); return CE_Failure; } /* -------------------------------------------------------------------- */ /* Get the geotransform, if there is one, so we can convert the */ /* vectors into georeferenced coordinates. */ /* -------------------------------------------------------------------- */ GDALDatasetH hSrcDS = GDALGetBandDataset( hSrcBand ); double adfGeoTransform[6] = { 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 }; if( hSrcDS ) GDALGetGeoTransform( hSrcDS, adfGeoTransform ); /* -------------------------------------------------------------------- */ /* The first pass over the raster is only used to build up the */ /* polygon id map so we will know in advance what polygons are */ /* what on the second pass. */ /* -------------------------------------------------------------------- */ int iY; GDALRasterFPolygonEnumerator oFirstEnum(nConnectedness); for( iY = 0; eErr == CE_None && iY < nYSize; iY++ ) { eErr = GDALRasterIO( hSrcBand, GF_Read, 0, iY, nXSize, 1, pafThisLineVal, nXSize, 1, GDT_Float32, 0, 0 ); if( eErr == CE_None && hMaskBand != NULL ) eErr = GPMaskImageData( hMaskBand, pabyMaskLine, iY, nXSize, pafThisLineVal ); if( iY == 0 ) oFirstEnum.ProcessLine( NULL, pafThisLineVal, NULL, panThisLineId, nXSize ); else oFirstEnum.ProcessLine( pafLastLineVal, pafThisLineVal, panLastLineId, panThisLineId, nXSize ); // swap lines float * pafTmp = pafLastLineVal; pafLastLineVal = pafThisLineVal; pafThisLineVal = pafTmp; GInt32 * panTmp = panThisLineId; panThisLineId = panLastLineId; panLastLineId = panTmp; /* -------------------------------------------------------------------- */ /* Report progress, and support interrupts. */ /* -------------------------------------------------------------------- */ if( eErr == CE_None && !pfnProgress( 0.10 * ((iY+1) / (double) nYSize), "", pProgressArg ) ) { CPLError( CE_Failure, CPLE_UserInterrupt, "User terminated" ); eErr = CE_Failure; } } /* -------------------------------------------------------------------- */ /* Make a pass through the maps, ensuring every polygon id */ /* points to the final id it should use, not an intermediate */ /* value. */ /* -------------------------------------------------------------------- */ oFirstEnum.CompleteMerges(); /* -------------------------------------------------------------------- */ /* Initialize ids to -1 to serve as a nodata value for the */ /* previous line, and past the beginning and end of the */ /* scanlines. */ /* -------------------------------------------------------------------- */ int iX; panThisLineId[0] = -1; panThisLineId[nXSize+1] = -1; for( iX = 0; iX < nXSize+2; iX++ ) panLastLineId[iX] = -1; /* -------------------------------------------------------------------- */ /* We will use a new enumerator for the second pass primariliy */ /* so we can preserve the first pass map. */ /* -------------------------------------------------------------------- */ GDALRasterFPolygonEnumerator oSecondEnum(nConnectedness); RPolygonF **papoPoly = (RPolygonF **) CPLCalloc(sizeof(RPolygonF*),oFirstEnum.nNextPolygonId); /* ==================================================================== */ /* Second pass during which we will actually collect polygon */ /* edges as geometries. */ /* ==================================================================== */ for( iY = 0; eErr == CE_None && iY < nYSize+1; iY++ ) { /* -------------------------------------------------------------------- */ /* Read the image data. */ /* -------------------------------------------------------------------- */ if( iY < nYSize ) { eErr = GDALRasterIO( hSrcBand, GF_Read, 0, iY, nXSize, 1, pafThisLineVal, nXSize, 1, GDT_Float32, 0, 0 ); if( eErr == CE_None && hMaskBand != NULL ) eErr = GPMaskImageData( hMaskBand, pabyMaskLine, iY, nXSize, pafThisLineVal ); } if( eErr != CE_None ) continue; /* -------------------------------------------------------------------- */ /* Determine what polygon the various pixels belong to (redoing */ /* the same thing done in the first pass above). */ /* -------------------------------------------------------------------- */ if( iY == nYSize ) { for( iX = 0; iX < nXSize+2; iX++ ) panThisLineId[iX] = -1; } else if( iY == 0 ) oSecondEnum.ProcessLine( NULL, pafThisLineVal, NULL, panThisLineId+1, nXSize ); else oSecondEnum.ProcessLine( pafLastLineVal, pafThisLineVal, panLastLineId+1, panThisLineId+1, nXSize ); /* -------------------------------------------------------------------- */ /* Add polygon edges to our polygon list for the pixel */ /* boundaries within and above this line. */ /* -------------------------------------------------------------------- */ for( iX = 0; iX < nXSize+1; iX++ ) { AddEdges( panThisLineId, panLastLineId, oFirstEnum.panPolyIdMap, oFirstEnum.pafPolyValue, papoPoly, iX, iY ); } /* -------------------------------------------------------------------- */ /* Periodically we scan out polygons and write out those that */ /* haven't been added to on the last line as we can be sure */ /* they are complete. */ /* -------------------------------------------------------------------- */ if( iY % 8 == 7 ) { for( iX = 0; eErr == CE_None && iX < oSecondEnum.nNextPolygonId; iX++ ) { if( papoPoly[iX] && papoPoly[iX]->nLastLineUpdated < iY-1 ) { if( hMaskBand == NULL || !GDALFloatEquals(papoPoly[iX]->fPolyValue, GP_NODATA_MARKER) ) { eErr = EmitPolygonToLayer( hOutLayer, iPixValField, papoPoly[iX], adfGeoTransform ); } delete papoPoly[iX]; papoPoly[iX] = NULL; } } } /* -------------------------------------------------------------------- */ /* Swap pixel value, and polygon id lines to be ready for the */ /* next line. */ /* -------------------------------------------------------------------- */ float *pafTmp = pafLastLineVal; pafLastLineVal = pafThisLineVal; pafThisLineVal = pafTmp; GInt32 *panTmp = panThisLineId; panThisLineId = panLastLineId; panLastLineId = panTmp; /* -------------------------------------------------------------------- */ /* Report progress, and support interrupts. */ /* -------------------------------------------------------------------- */ if( eErr == CE_None && !pfnProgress( 0.10 + 0.90 * ((iY+1) / (double) nYSize), "", pProgressArg ) ) { CPLError( CE_Failure, CPLE_UserInterrupt, "User terminated" ); eErr = CE_Failure; } } /* -------------------------------------------------------------------- */ /* Make a cleanup pass for all unflushed polygons. */ /* -------------------------------------------------------------------- */ for( iX = 0; eErr == CE_None && iX < oSecondEnum.nNextPolygonId; iX++ ) { if( papoPoly[iX] ) { if( hMaskBand == NULL || !GDALFloatEquals(papoPoly[iX]->fPolyValue, GP_NODATA_MARKER) ) { eErr = EmitPolygonToLayer( hOutLayer, iPixValField, papoPoly[iX], adfGeoTransform ); } delete papoPoly[iX]; papoPoly[iX] = NULL; } } /* -------------------------------------------------------------------- */ /* Cleanup */ /* -------------------------------------------------------------------- */ CPLFree( panThisLineId ); CPLFree( panLastLineId ); CPLFree( pafThisLineVal ); CPLFree( pafLastLineVal ); CPLFree( pabyMaskLine ); CPLFree( papoPoly ); return eErr; #endif // OGR_ENABLED }
void ContestDijkstra::AddEdges(const ScanTaskPoint origin) { AddEdges(origin, 0); }