Tuesday, December 20, 2011

PDF-font-embedded problem or acrobat compatibility problem with PDFExpress ??

Have you came through the font embedding problem or acrobat compatibility ? I got these problem when I was submitting my final camera ready paper to IEEE pdf-express. When first time I submitted my paper then I got the font embedding problem like :
              
Error  Font Times-Roman is not embedded (832x)
Error  Font Times-BoldItalic is not embedded (14x)
Error  Font Times-Bold is not embedded (32x)
Error  Font Times-Italic is not embedded (66x)

I embedded all fonts and submitted second time and then I got the error :

Error Acrobat version is less than 5.0

But after third submission I got the message, paper has been passed all the basic formatting requirement. So I thought to share the solution with you guys.
Here is the steps i followed:

1> latex file.tex
2> dvips file.dvi -o file.ps
3> ps2pdf -dEmbedAllFonts=true -dSubsetFonts=true -dEPSCrop=true -dPDFSETTINGS=/prepress file.ps

Alternate solution:
Use ghost script pdf printer to embed all fonts and convert into PDF.

gs -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=a4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sOutputFile=Final.pdf Final.ps

Some more same kind of solution: Link1 Link2

Good luck !!

Friday, November 25, 2011

Implemenations of BFS & DFS traversal for Graph using adjancency Matrix (Java)


import java.io.BufferedInputStream;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

/**
 *
 * @author santosh
 */
public class AdjMatGraph {

    class Queue {

        LinkedList queueHead = new LinkedList();
        int size;

        public void enqueue(GNode gn) {
            size++;
            queueHead.add(gn);
        }

        public GNode dequeue() {
            if (size > 0) {
                size--;
                return queueHead.removeLast();
            }

            return null;
        }

        public GNode peek() {
            return queueHead.getFirst();
        }

        public GNode tail() {
            return queueHead.getLast();
        }

        public int qSize() {
            return size;
        }

        public boolean isEmpty() {
            if (size <= 0) {
                return true;
            } else {
                return false;
            }
        }
    }

    private class GNode {

        int vLabel;
        boolean isVisited;
    }
    private int adjMat[][];
    private int noOfEdges;
    private int noOfVertex;
    private GNode vertex[];
    private Stack stack;
    private Queue queue;

    public AdjMatGraph() {

        adjMat = new int[100][100];

        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < 100; j++) {
                adjMat[i][j] = 0;
            }
        }

        noOfEdges = 0;
        noOfVertex = 0;
        vertex = new GNode[100];

        for (int k = 0; k < 100; k++) {
            vertex[k] = new GNode();
            vertex[k].isVisited = false;
            vertex[k].vLabel = -1;
        }

        stack = new Stack();
        queue = new Queue();
    }

    public void setNoEdges(int val) {
        noOfEdges = val;
    }

    public void setNoVertex(int val) {
        noOfVertex = val;
        for (int i = 1; i <= val; i++) {
            vertex[i - 1].vLabel = i;
        }
    }

    public int findVertex(int v) {

        for (int i = 0; i < noOfVertex; i++) {
            if (vertex[i].vLabel == v) {
                return i;
            }
        }

        return -1;
    }

    public void addEdge(int v1, int v2) {

        int index1 = findVertex(v1);
        int index2 = findVertex(v2);

        if (index1 != -1 && index2 != -2) {
            adjMat[index1][index2] = 1;
            adjMat[index2][index1] = 1;
        }
    }

    public void printMatrix() {

        for (int i = 0; i < noOfVertex; i++) {
            System.out.println();
            for (int j = 0; j < noOfVertex; j++) {
                System.out.print("\t" + adjMat[i][j]);
            }
        }
    }

    public GNode getAdjNode(GNode node) {

        int index = findVertex(node.vLabel);

        if (index != -1) {
            for (int i = 0; i < noOfVertex; i++) {
                if (adjMat[index][i] == 1 && !vertex[i].isVisited) {
                    // System.out.println("GetAdj: " + vertex[i].vLabel);
                    return vertex[i];
                }
            }
        }

        return null;
    }

    public void DFS() {
        System.out.print("DFS: ");
        for (int i = 0; i < noOfVertex; i++) {
            if (!vertex[i].isVisited) {
                stack.add(vertex[i]);
                while (!stack.isEmpty()) {
                    GNode tmp = stack.pop();
                    if (!tmp.isVisited) {
                        tmp.isVisited = true;
                        System.out.print("\t" + tmp.vLabel);

                        // get adjacent node
                        GNode t2 = getAdjNode(tmp);
                        if (t2 != null) {
                            stack.add(t2);
                        }
                    }
                }
            }
        }

        for (int i = 0; i < noOfVertex; i++) {
            vertex[i].isVisited = false;
        }
    }

    public void BFS() {
        System.out.print("\nBFS: ");
        for (int i = 0; i < noOfVertex; i++) {
            if (!vertex[i].isVisited) {
                vertex[i].isVisited = true;
                System.out.print("\t" + vertex[i].vLabel);
                queue.enqueue(vertex[i]);
                while (!queue.isEmpty()) {
                    GNode tmp = queue.dequeue();
                    GNode v = null;
                    tmp.isVisited = true;
                    while ((v = getAdjNode(tmp)) != null) {
                        v.isVisited = true;
                        System.out.print("\t" + v.vLabel);
                        queue.enqueue(v);
                    }
                }
            }
        }
        System.out.println();
        for (int i = 0; i < noOfVertex; i++) {
            vertex[i].isVisited = false;
        }
    }

    /**
     * This section contains function to help implement Directed Graph
     * and topological sorting.
     */
    public void addDirectEdge(int v1, int v2) {

        int index1 = findVertex(v1);
        int index2 = findVertex(v2);

        if (index1 != -1 && index2 != -1) {
            adjMat[index1][index2] = 1;
        }
    }

    public int noSuccessor() {

        for (int i = 0; i < noOfVertex; i++) {
            boolean isVisited = false;
            for (int j = i; j < noOfVertex; j++) {
                if (adjMat[i][j] > 0) {
                    isVisited = true;
                    break;
                }
            }
            if (!isVisited) {
                return i;
            }
        }

        return -1;
    }

    public void deleteVertex(int index) {

        //int index = findVertex(v);
       
        if (index != noOfVertex - 1) {

           // System.out.println("No of Vertex: " + noOfVertex + "\tindex: " + index);
           
            for (int i = index; i < noOfVertex-1; i++) {
                vertex[i].vLabel = vertex[i + 1].vLabel;
           
                moveRowUp(i, noOfVertex); // shift all rows next to given vertex to 1 row up.
               
                moveColLeft(i, noOfVertex-1); // shift all column to 1 left from given vertex.

            }
        }

        noOfVertex--;

    }

    public void topologicalSorting(){
        int orig_nVerts = noOfVertex;
       
        while(noOfVertex > 0){
            int currVertex = noSuccessor();
           
            if(currVertex == -1){
                System.out.println("There is Cycle !!");
                return;
            }
           
            //System.out.println("Total Vertex: " + noOfVertex + "\tCurrent Vertex: " + vertex[currVertex].vLabel + "\tIndex: " + currVertex);
           
            // insert vertex label in sorted array (start at end)
            sortedArray[noOfVertex-1] = vertex[currVertex].vLabel;
           
            // delete vertex
            deleteVertex(currVertex);
           
            /*
            System.out.println();
            printMatrix();
            System.out.println();
             *
             */
        }
       
        System.out.print("Topological Sorted: ");
       
        for(int i=0; i            System.out.print("\t" + sortedArray[i]);
        }
       
        System.out.println();
    }
    // ------------------
    private void moveRowUp(int row, int length) {
        for (int col = 0; col < length; col++) {
            adjMat[row][col] = adjMat[row + 1][col];
        }
    }
// ------------------

    private void moveColLeft(int col, int length) {
        for (int row = 0; row < length; row++) {
            adjMat[row][col] = adjMat[row][col + 1];
        }
    }
// ------------------------------------------------------------


    public static void main(String args[]) {

        AdjMatGraph graph = new AdjMatGraph();
        Scanner stdin = new Scanner(new BufferedInputStream(System.in));

        System.out.println("Please enter the #vertex #Edges !!");
        graph.setNoVertex(stdin.nextInt());
        graph.setNoEdges(stdin.nextInt());

        System.out.println("Please enter the Edges And enter non-numeric character to end !!");

        while (true) {
            if (stdin.hasNextInt()) {
                //System.out.println(stdin.nextInt());
                graph.addEdge(stdin.nextInt(), stdin.nextInt());

                /* use this function to add edge in case graph is directed graph */

                // graph.addDirectEdge(stdin.nextInt(), stdin.nextInt());
            } else {
                break;
            }
        }

        graph.printMatrix();
        System.out.println("\n");
        graph.DFS();
        System.out.println();
        graph.BFS();


         
        // graph.topologicalSorting();
    }
}

Tuesday, November 22, 2011

Binary Tree Implementation (Java Code)

Node.java
/**
 *
 * @author santosh
 */

public class Node {
   
     Node left;
     Node right;
     Node parent;
     int     val;
     int     height;
     int     balanceFactor;
     int     NaV = -99999999; // not a value.
   
    public Node(){
        left = right = parent = null;
        val = height = balanceFactor = NaV;
    }
   
    public Node(int val){
        left = right = parent = null;
        this.val = val;
        height = balanceFactor = NaV;
    }
   
    public Node(int val, int key){
        left = right = parent = null;
        this.val = val;
        this.balanceFactor = key;
        height = NaV;
    }
}

BST.java

/**
 *
 * @author santosh
 */
public class BST {

    private Node root;
   
    public BST(){
        root = null;
    }
   
    /**
     * Insert a node in given tree.
     * @param val
     */
    public void insert(int val){
       
        Node t = new Node(val);
        if(root == null){
            root = t;
            return;
        }else{
            Node temp = root, prev = null;
            while(temp != null){
                prev = temp;
                if(val > temp.val){
                    temp = temp.right;
                }else{
                    temp = temp.left;
                }
            }
           
            t.parent = prev; // assign the parent to new node;
           
            if(val > prev.val)
                prev.right = t;
            else
                prev.left = t;
        }
        return;
    }
   
    /**
     * Find the node whose data is given.
     * @param t
     * @param val
     * @return
     */
    public Node findNode(Node t, int val){
       
        Node temp = null;
       
        if(t != null && t.val == val)
            return t;
       
        if(t.left != null)
            temp = findNode(t.left, val);
        if(temp == null & t.right != null)
            temp = findNode(t.right, val);
       
        return temp;
    }
   
    /**
     * Returns the min value in a non-empty binary search tree.
     * @param t
     * @return
     */
    public Node findMin(Node t){
       
        if(t != null && t.left == null)
            return t;
        else
            return findMin(t.left);
    }
   
    /**
     * Returns the min value in a non-empty binary search tree.
     * @param t
     * @return
     */
    public Node findMax(Node t){
       
        if(t != null && t.right == null)
            return t;
        else
            return findMax(t.right);
    }
   
    /**
     * Print path of each leaf node in recursive order.
     * @param sum
     * @param t
     * @return
     */
    public int printPath(int sum, Node t){
       
        while(t != null){
            System.out.print("\t" + t.val);
            sum += t.val;
            t = t.parent;
        }
        return sum;
    }
   
    /**
     * Print leaf nodes
     * @param t
     */
    public void printLeafNodes(Node t){
       
        if(t != null && t.left == null && t.right == null){
            System.out.print("\t" + t.val);
        }
       
        if(t != null){
            printLeafNodes(t.left);
            printLeafNodes(t.right);
        }
       
        return;
    }
   
    /**
     * find path for each leaf node
     * @param t
     */
    public void findPath(Node t){
        if(t != null && t.left == null && t.right == null) {
            System.out.print("Path: ");
            int sum = printPath(0, t);
            System.out.println("\tSum: " + sum);
        }
        if(t != null){
            findPath(t.left);
            findPath(t.right);
        }
        return;
    }
   
    /**
     * Check if any path has given sum.
     * @param t
     * @param sum
     * @return
     */
    public boolean hasPathSum(Node t, int sum){
        if(t == null)
            return (sum == 0);
        else{
            sum -= t.val;
            return hasPathSum(t.left, sum) || hasPathSum(t.right, sum);
        }
    }
   
    /**
     * Make mirror image of given tree.
     * @param t
     */
    public void mirrorTree(Node t){
       
        if(t == null)
            return;
       
        Node temp = null;
        mirrorTree(t.left);
        mirrorTree(t.right);
       
        temp = t.left;
        t.left = t.right;
        t.right = temp;
       
        return;
    }
   
    /**
     * For each node in a binary search tree, create a new duplicate node, and insert
     * the duplicate as the left child of the original node.
     * The resulting tree should still be a binary search tree. So the tree...
     *          2
     *         / \
     *        1   3
     * Is changed to...
     *          2
     *         / \
     *        2   3
     *      /    /
     *     1    3
     *    /
     *   1
     *
     **/
    public void doubleTree(Node t){
       
        if(t == null)
            return;
       
        Node oldLeft = null;
        doubleTree(t.left);
        doubleTree(t.right);
       
        oldLeft = t.left;
        t.left = new Node(t.val);
        t.left.parent = t; // assign parent to new node
        t.left.left = oldLeft;
        if(t.left.left != null)
            t.left.left.parent = t.left; // update the parent for old node
       
    }
   
    /**
     * Given two trees, return true if they are structurally identical.
     * @param t1
     * @param t2
     * @return
     */
    public boolean checkMatchingTree(Node t1, Node t2){
     
        // both empty
        if(t1 == null && t2 == null)
            return true;
       
        else if(t1 != null && t2 != null)
            return (t1.val == t2.val &&
                    checkMatchingTree(t1.left, t2.left) &&
                    checkMatchingTree(t1.right, t2.right));
        else // one of them empty
            return false;
    }
   
    /**
     * Count number of nodes in a given tree.
     * @param t
     * @return
     */
    public int countTNode(Node t){
       
        if(t == null)
            return 0;
        else
            return (countTNode(t.left) + 1 + countTNode(t.right));
           
    }
   
    /**
     * For the key values 1...numKeys, how many structurally unique binary
     * search trees are possible that store those keys?
     * Strategy: consider that each value could be the root.
     * Recursively find the size of the left and right subtrees.
     * @param key
     * @return
     */
    public int countTrees(int key){
       
        if(key <= 1)
            return 1;
        else{
            // there will be one value at the root, with whatever remains
            // on the left and right each forming their own subtrees.
            // Iterate through all the values that could be the root...
            int sum = 0;
            int lht, rht, rt = 0;
           
            for(rt=1; rt<=key; rt++ ){
                lht = countTrees(rt-1);
                rht = countTrees(key-rt);
               
                // number of possible trees with this root == left*right
                sum += lht * rht;
            }
           
            return sum;
        }
    }
   
    /**
     * Find the maximum depth of a given tree.
     * @param t
     * @return
     */
    public int maxDept(Node t){
       
        if(t == null)
            return 0;
       
        int lDepth = maxDept(t.left);
        int rDepth = maxDept(t.right);
       
        return (lDepth>rDepth)?(lDepth+1):(rDepth+1);
       
    }
   
    /**
     * Print the tree in In-Order.
     * @param t
     */
    public void printInOrder(Node t){
        if(t == null)
            return;
       
        printInOrder(t.left);
        System.out.print("\t"+t.val);
        printInOrder(t.right);
    }
   
    /**
     * print the tree in Post-Order.
     * @param t
     */
    public void printPostOrder(Node t){
        if(t == null)
            return;
       
        printPostOrder(t.left);
        printPostOrder(t.right);
        System.out.print("\t"+t.val);
       
    }
   
    /**
     * Print the tree in Pre-order.
     * @param t
     */
    public void printPreOrder(Node t){
        if(t == null)
            return;
       
        System.out.print("\t"+t.val);
        printPreOrder(t.left);
        printPreOrder(t.right);
    }
   
    /**
     * Get root of the node.
     * @return
     */
    public Node getRoot(){
        return root;
    }
}

Monday, November 14, 2011

NS2: How add/implement a new protocol into ns2 network simulator

I have tried adding new protocol called "MyPing" using existing code of "ping" protocol. I have followed following procedure :

1. copy the ping.h & ping.cc to ns2-xx/apps and renamed it myping.h & myping.cc respectively.

2. Define MyPing Packet type in packet.h as:


a)       // insert new packet types here
          static const packet_t PT_MYPING = 62;
          static packet_t       PT_NTYPE = 63; // This MUST be the LAST one

b)         class p_info {  .........
              static bool data_packet(packet_t type) {
              ..................................
              (type) == PT_MYPING\
             -----------------------------
           static void initName()
           ------------------------------
           name_[PT_MYPING]="MyPing";
     //------------------------------------
           name_[PT_NTYPE]= "undefined";
          .....................................................


c)      #define DATA_PACKET(type) ( (type) == PT_TCP || \
            ...........................................
             (type) == PT_MYPING \
             ...........................................


3)  Define default value of MyPing agent in ns-default.tcl
    Agent/MyPing packet_size 64


4) Edit Makefile inside ns2-xx dir and add "apps/myping.o"  next to "apps/ping.o" 


5) make clean and then make


You may follow these links for more information related to implementation:
http://www.isi.edu/nsnam/ns/tutorial/nsnew.html
http://nile.wpi.edu/NS/

Thanks
--

Wednesday, November 9, 2011

Have you tried to model your life?

If you have to model your Life what kind of model you will use? This question came in to my mind when I was reading something & came across sine wave.  So i thought why don't I try to model my life on sine wave & see how it fits. What I fund that is sounds interesting to me. The best thing about sine wave is, it periodically changing from high to low amplitude & vice-versa. Our life too have up & down that keeps changing with time. Some time it may be at its extreme either it could be up or down.
Here is life cycle that goes along with time....


fun time over....
bye

Monday, October 17, 2011

Move Window Buttons to Right in Ubuntu

Ubuntu 10.04 / 10.10 :

Step1: Press Alt+F2 to bring up the Run Application dialog box, enter “gconf-editor” in the text field, and click on Run.

Step2:  Click on the + button next to the “apps” folder, then beside “metacity” in the list of folders expanded for apps, and then click on the “general” folder.

Step3:  The button layout can be changed by changing the “button_layout” key and Change the text in the Value text field to:
                           
                                 menu:maximize,minimize,close

Ubuntu 11.04 / 11.10 : 

Run the following command on terminal :

gconftool-2 --set /apps/metacity/general/button_layout \
 --type string "menu:minimize,maximize,close"

Ubuntu 12.04 / 12.10 : 

Run the following command on terminal:
 
gsettings set org.gnome.desktop.wm.preferences \ 
button-layout ':minimize,maximize,close'

Or, open dconf-editor and navigate to org/gnome/desktop/wm/preferences, and then change the value of button layout to :minimize,maximize,close

Tuesday, September 13, 2011

[Bibtext][Latex] RFC citation issues into conference paper or journal

Bibtex Entry:

Citing RFC :

@techreport{rfc2358,
   AUTHOR = "Flick, J and Johnson, J.",
   TITLE = "{Definitions of Managed Objects for the Ethernet-like}",
   HOWPUBLISHED = {Internet Requests for Comments},
   TYPE="{RFC}",
   NUMBER=2358,
   PAGES = {},
   YEAR = {1998},
   MONTH = {June},
   ISSN = {2070-1721},
   PUBLISHER = "{RFC Editor}",
   INSTITUTION = "{RFC Editor}",
   URL={http://www.rfc-editor.org/rfc/rfc2358.txt}
  }

Citing RFC Drafts:

   @TECHREPORT{draft-ipng-gseaddr-00.txt,
   AUTHOR="M. O'Dell",
   TITLE="{GSE: An Alternate Addressing Architecture for IPv6}",
   HOWPUBLISHED="{Working Draft}",
   TYPE="{Internet-Draft}",
   NUMBER="draft-ipng-gseaddr-00.txt",
   INSTITUTION="{IETF Secretariat}",
   DAY=24,
   MONTH=Feb,
   YEAR=1997
   }
 
More information:
1. Recommendations of a committee on RFC citation issues draft-carpenter-rfc-citation-recs-01

2. Using The ISSN (International Serial Standard Number) as URN (Uniform Resource Names) within an ISSN-URN Namespace