giraph-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jyoti Yadav <rao.jyoti26ya...@gmail.com>
Subject Re: Need your help to serialize an boolean array....
Date Wed, 20 Nov 2013 09:13:15 GMT
Thanks Sebastian for your reply...

All three files are shown below..

1.Main program file..
2.VertexValueWritable file.
3.MessageWritable file..



..................................************************.........................................


package org.apache.giraph.examples;
import org.apache.giraph.examples.utils.ClosenessVertexValueWritable;
import org.apache.giraph.graph.BasicComputation;
import org.apache.giraph.conf.LongConfOption;
import org.apache.giraph.edge.Edge;
import org.apache.giraph.graph.Vertex;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.log4j.Logger;

import java.io.IOException;


public class Closeness extends BasicComputation<LongWritable,
ClosenessVertexValueWritable, FloatWritable, ClosenessMessageWritable>
{
    private static final Logger LOG =Logger.getLogger(Closeness.class);
    @Override
        public void compute(Vertex<LongWritable,
ClosenessVertexValueWritable, FloatWritable>
vertex,Iterable<ClosenessMessageWritable> messages) throws IOException
    {
        if(getSuperstep()==0)
        {
            boolean[] bitstring=new boolean[128];
            for(int i=0;i<128;i++)
            {
                bitstring[i]=false;
            }
             vertex.setValue(new
ClosenessVertexValueWritable(0.0,0.0,bitstring));
                boolean[] bitstring1=new boolean[128];
                bitstring1=vertex.getValue().get_previous_bitstring();


                 for (Edge<LongWritable, FloatWritable> edge :
vertex.getEdges())
                {


                    sendMessage(edge.getTargetVertexId(), new
ClosenessMessageWritable(bitstring));

                             System.out.println("superstep is
="+getSuperstep()+"vertex is ="+vertex.getId().get());



                }

        }

        if(getSuperstep()==1)
        {
            boolean[] bitstring2=new boolean[128];

            for (ClosenessMessageWritable message : messages)
            {
                System.out.println("superstep is ="+getSuperstep()+"vertex
is ="+vertex.getId().get());


                bitstring2=message.get_previous_bitstring();

            }


            vertex.voteToHalt();
        }





    }
}



.............................................*************************************.....................................................



package org.apache.giraph.examples.utils;

import java.io.*;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.WritableComparator;
import java.util.Arrays;










public class ClosenessVertexValueWritable implements Writable {

  private double vertex_value;
  private double previous_no_of_neighbors;
  private boolean[] previous_bitstring;

  public ClosenessVertexValueWritable()
    {
        vertex_value=0.0;
        previous_no_of_neighbors=0.0;
        previous_bitstring=new boolean[128];

    }

  public ClosenessVertexValueWritable(double vertex_value1,double
previous_no_of_neighbors1,boolean[] previous_bitstring1)
    {

    vertex_value=vertex_value1;
    previous_no_of_neighbors=previous_no_of_neighbors1;
    previous_bitstring=new boolean[128];
    previous_bitstring=previous_bitstring1;




  public double get_vertex_value() { return vertex_value; }
  public double get_previous_no_of_neighbors() { return
previous_no_of_neighbors; }
  public boolean[] get_previous_bitstring() { return previous_bitstring; }


 @Override
  public void readFields(DataInput in) throws IOException {
         vertex_value=in.readDouble();
    previous_no_of_neighbors=in.readDouble();

        for(int i=0;i<128;i++)
    {
     this.previous_bitstring[i] = in.readBoolean();
    }
  }
 @Override
  public void write(DataOutput out) throws IOException {
          out.writeDouble(vertex_value);

     out.writeDouble(previous_no_of_neighbors);

    for(int i=0;i<128;i++)
    {
     out.writeBoolean(previous_bitstring[i]);
    }


  }

@Override
  public String toString()
  {
        String str="";

        //str=Arrays.toString(previous_bitstring);

        return Double.toString(vertex_value)+
Double.toString(previous_no_of_neighbors)+Arrays.toString(previous_bitstring);
   }



}


..................................*****************************************...................................................



package org.apache.giraph.examples;

import java.io.*;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.WritableComparator;
import java.util.Arrays;


public class ClosenessMessageWritable implements Writable {



    private int size;

    private boolean[] previous_bitstring;

  public ClosenessMessageWritable() {}

  public ClosenessMessageWritable(boolean[] previous_bitstring1)
    {

    size=128;
    previous_bitstring=new boolean[128];
    previous_bitstring=previous_bitstring1;




    }


  public boolean[] get_previous_bitstring() { return previous_bitstring; }

 @Override
  public void readFields(DataInput in) throws IOException {


    size=in.readInt();

        for(int i=0;i<size;i++)
        {
            boolean b=in.readBoolean();
             previous_bitstring[i] = b;
        }


  }
 @Override
  public void write(DataOutput out) throws IOException {

     out.writeInt(size);

    for(int i=0;i<size;i++)
    {
        boolean b=previous_bitstring[i];
     out.writeBoolean(b);
    }



  }


@Override
  public String toString()
  {
        String str="";

        str=Arrays.toString(previous_bitstring);

        return str;
   }




}


Please check where i am going wrong...
Thanks...



On Wed, Nov 20, 2013 at 1:31 PM, Sebastian Schelter <ssc.open@googlemail.com
> wrote:

> What errors do you exactly get? Can you show the whole implementation of
> your vertex?
>
> On 20.11.2013 08:42, Jyoti Yadav wrote:
> > Hi folks..
> >
> > I am implementing one program where I need to pass message as boolean
> > array..
> > While implementing my MyMessageWritable.java class,I need to define
> > readfields() and write() functions...
> >
> > I tried my luck but failed...Program is compiling fine but not running...
> >
> >
> > I am taking boolean array as
> >
> > boolean[] bitstring=new boolean[128];
> >
> >
> > pls help...I am badly tangled...
> >
> > Thanks
> >
> > Jyoti
> >
>
>

Mime
View raw message