Exemplo n.º 1
0
Arquivo: graph.c Projeto: 8l/csolve
void
PrintNeighbors(Vertices * vertex)
{
  Edges * edge;

  edge = EDGES(vertex);
  while(edge != NULL)
  {
    printf(" %d(%d)[%d]", ID(VERTEX(edge)), WEIGHT(edge), ID(SOURCE(edge)));
    edge = NEXT_EDGE(edge);
  }
}
Exemplo n.º 2
0
Arquivo: graph.c Projeto: 8l/csolve
void
Connect(Vertices * vertex1, Vertices * vertex2)
{
  int    weight;
  Edges * edge;

  weight = GET_WEIGHT;

  edge = NewEdge();
  WEIGHT(edge) = weight;
  SOURCE(edge) = vertex1;
  VERTEX(edge) = vertex2;
  NEXT_EDGE(edge) = EDGES(vertex1);
  EDGES(vertex1) = edge;
  
  edge = NewEdge();
  WEIGHT(edge) = weight;
  SOURCE(edge) = vertex2;
  VERTEX(edge) = vertex1;
  NEXT_EDGE(edge) = EDGES(vertex2);
  EDGES(vertex2) = edge;
}
Exemplo n.º 3
0
Arquivo: ft.c Projeto: 8l/csolve
Vertices *
MST(Vertices * graph)
{
  HeapP * heap;
  Vertices * vertex;
  Edges * edge;
  ;

  InitFHeap();

  /*
   * key(s) = 0;
   * key(v) = infty for v != s;
   * init heap;
   * make a heap;
   * put s in heap;
   */
  vertex = graph;
  KEY(vertex) = 0;
  heap = MakeHeap();
  (void)Insert(&heap, (Item *)vertex);

  vertex = NEXT_VERTEX(vertex);
  while(vertex != graph)
  {
    KEY(vertex) = PLUS_INFINITY;
    vertex = NEXT_VERTEX(vertex);
  }
  while(vertex != graph);

  vertex = FindMin(heap);
  while(vertex != NULL_VERTEX)
  {
    heap = DeleteMin(heap);
    KEY(vertex) = MINUS_INFINITY;
    edge = EDGES(vertex);
    while(edge != NULL_EDGE)
    {
      if(WEIGHT(edge) < KEY(VERTEX(edge)))
      {
        KEY(VERTEX(edge)) = WEIGHT(edge);
        CHOSEN_EDGE(VERTEX(edge)) = edge;
        (void)Insert(&heap, VERTEX(edge));
      }
      edge = NEXT_EDGE(edge);
    }
    vertex = FindMin(heap);
  }
  ;
  return(graph);
}
mlib_status mlib_ImageConvClearEdge_Fp(mlib_image     *img,
                                       mlib_s32       dx_l,
                                       mlib_s32       dx_r,
                                       mlib_s32       dy_t,
                                       mlib_s32       dy_b,
                                       const mlib_d64 *color,
                                       mlib_s32       cmask)
{
  mlib_s32 img_width  = mlib_ImageGetWidth(img);
  mlib_s32 img_height = mlib_ImageGetHeight(img);
  mlib_s32 channel    = mlib_ImageGetChannels(img);

  if (dx_l + dx_r > img_width) {
    dx_l = img_width;
    dx_r = 0;
  }

  if (dy_t + dy_b > img_height) {
    dy_t = img_height;
    dy_b = 0;
  }

  if (channel == 1) cmask = 1;

  switch (mlib_ImageGetType(img)) {
    case MLIB_FLOAT:
      EDGES(channel,mlib_f32, cmask);
      break;
    case MLIB_DOUBLE:
      EDGES(channel,mlib_d64, cmask);
      break;
    default:
      return MLIB_FAILURE;
  }

  return MLIB_SUCCESS;
}
Exemplo n.º 5
0
Arquivo: graph.c Projeto: 8l/csolve
Vertices *
NewVertex()
{
  Vertices * vertex;

  vertex = (Vertices *)malloc(sizeof(Vertices));

  if(vertex == NULL)
  {
    fprintf(stderr, "Could not malloc\n");
    exit(1);
  }

  ID(vertex) = id++;
  EDGES(vertex) = NULL;
  NEXT_VERTEX(vertex) = NULL;

  return(vertex);
}
Exemplo n.º 6
0
Arquivo: graph.c Projeto: 8l/csolve
int
Duplicate(Vertices * vertex1, Vertices * vertex2)
{
  Edges * edge;

  edge = EDGES(vertex1);

  while(edge != NULL_EDGE)
  {
    if(VERTEX(edge) == vertex2)
    {
      return(TRUE);
    }

    edge = NEXT_EDGE(edge);
  }

  return(FALSE);
}
Exemplo n.º 7
0
Arquivo: graph.c Projeto: 8l/csolve
Vertices *
GenTree(int nVertex)
{
  int       i;
  int       weight;
  Vertices * vertex;
  Vertices * graph;
  Edges * edge;

  graph = NewVertex();
  NEXT_VERTEX(graph) = graph;

  for(i = 1; i < nVertex; i++)
  {
    vertex = NewVertex();
    edge = NewEdge();

    /*
     * The newly created vertex has one edge ...
     */
    EDGES(vertex) = edge;

    /*
     * ... which is connected to the graph so far generated.  The connection
     * point in the graph is picked at random.
     */
    VERTEX(edge) = PickVertex(graph, random() % i);
    weight = GET_WEIGHT;
    WEIGHT(edge) = weight;
    SOURCE(edge) = vertex;

    /*
     * Link the new vertex into the graph.
     */
    NEXT_VERTEX(vertex) = NEXT_VERTEX(graph);
    NEXT_VERTEX(graph) = vertex;

    /*
     * Add an edge to the vertex randomly picked as the connection point.
     */
    edge = NewEdge();
    WEIGHT(edge) = weight;
    SOURCE(edge) = VERTEX(EDGES(vertex));
    VERTEX(edge) = vertex;
    NEXT_EDGE(edge) = EDGES(VERTEX(EDGES(vertex)));
    EDGES(VERTEX(EDGES(vertex))) = edge;
   }

  return(graph);
}