// Path: NavigationDG/src/org/dg/main/Edge.java
// public class Edge {
// 	public Edge(Node _from, Node _to, double _distance) {
// 		from = _from;
// 		to = _to;
// 		distance = _distance;
// 	}
// 	
// 	public Edge(Edge e) {
// 		from = e.from;
// 		to = e.to;
// 		distance = e.distance;
// 	}
// 	
// 	public void revert() {
// 		Node tmp = from;
// 		from = to;
// 		to = tmp;
// 		
// 		tmp = from.previousNodeForNav;
// 		from.previousNodeForNav = to.previousNodeForNav;
// 		to.previousNodeForNav = tmp;
// 	}
// 	
// 	public Node from, to;
// 	public double distance;
// }
// 
// Path: NavigationDG/src/org/dg/main/Node.java
// public class Node {
// 	
// 	private int id;
// 	private double px, py;
// 	private double x, y;
// 	
// 	public Node previousNodeForNav;
// 	
// 	public Node (int id, double px, double py) {
// 		init(id, px, py, 0.0, 0.0);
// 	}
// 	
// 	public Node(int id, double px, double py, double x, double y) {
// 		init(id, px, py, x, y);
// 	}
// 	
// 	public Node(Node n) {
// 		init(n.id, n.px, n.py, n.x, n.y);
// 	}
// 	
// 	private void init(int _id, double _px, double _py, double _x, double _y) {
// 		this.id = _id;
// 		this.px = _px;
// 		this.py = _py;
// 		this.x = _x;
// 		this.y = _y;
// 	}
// 	
// 	public int getId() {
// 		return id;
// 	}
// 	
// 	public double getPx() {
// 		return px;
// 	}
// 	
// 	public double getPy() {
// 		return py;
// 	}
// 	
// 	public double getX() {
// 		return x;
// 	}
// 	
// 	public double getY() {
// 		return y;
// 	}
// 	
// 	public double euclideanDistance(Node b) {
// 		return Math.sqrt( Math.pow(x - b.getX(),2) + Math.pow(y - b.getY(),2));
// 	}
// 	
// 	public double euclideanDistance(double posX, double posY) {
// 		return euclideanDistance(new Node(0, 0, 0, posX, posY));
// 	}
// 
// }
// 
// Path: NavigationDG/src/org/dg/wifi/MyScanResult.java
// public class MyScanResult {
// 	public MyScanResult(String _BSSID, int _level) {
// 		BSSID = _BSSID;
// 		level = _level;
// 		networkName = "";
// 	}
// 	
// 	public MyScanResult(String _BSSID, int _level, String _networkName) {
// 		BSSID = _BSSID;
// 		level = _level;
// 		networkName = _networkName;
// 	}
// 	
// 	public MyScanResult(String _BSSID, int _level, String _networkName, int _frequency) {
// 		BSSID = _BSSID;
// 		level = _level;
// 		networkName = _networkName;
// 		frequency = _frequency;
// 	}
// 	
// 	
// 	public int level, frequency;	
// 	public String BSSID;
// 	public String networkName;
// }


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Scanner;
import org.dg.main.Edge;
import org.dg.main.Node;
import org.dg.wifi.MyScanResult;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.util.Log;

	/**
	 * Checks and creates a directory for a new map
	 * 
	 * @param mapName
	 * @return
	 */
	private String creatingSaveMapDirectory(String mapName) {
		// Setting the directory of output
		String pathName = String.format(Locale.getDefault(), Environment
				.getExternalStorageDirectory().toString()
				+ "/OpenAIL/PriorData/" + mapName + "/");

		// Create directory if it doesn't exist
		File folder = new File(pathName);
		if (!folder.exists()) {
			folder.mkdir();
		}
		return pathName;
	}

	/**
	 * Saves the provided image in a map-compatible format
	 * 
	 * @param image
	 * @param pathName
	 */
	private void saveImageOfMapPoint(int mapPointId, Mat image, String pathName) {
		// Creating directory if needed
		File folder = new File(pathName + "images/");
// Path: NavigationDG/src/org/dg/main/Edge.java
// public class Edge {
// 	public Edge(Node _from, Node _to, double _distance) {
// 		from = _from;
// 		to = _to;
// 		distance = _distance;
// 	}
// 	
// 	public Edge(Edge e) {
// 		from = e.from;
// 		to = e.to;
// 		distance = e.distance;
// 	}
// 	
// 	public void revert() {
// 		Node tmp = from;
// 		from = to;
// 		to = tmp;
// 		
// 		tmp = from.previousNodeForNav;
// 		from.previousNodeForNav = to.previousNodeForNav;
// 		to.previousNodeForNav = tmp;
// 	}
// 	
// 	public Node from, to;
// 	public double distance;
// }
// 
// Path: NavigationDG/src/org/dg/main/Node.java
// public class Node {
// 	
// 	private int id;
// 	private double px, py;
// 	private double x, y;
// 	
// 	public Node previousNodeForNav;
// 	
// 	public Node (int id, double px, double py) {
// 		init(id, px, py, 0.0, 0.0);
// 	}
// 	
// 	public Node(int id, double px, double py, double x, double y) {
// 		init(id, px, py, x, y);
// 	}
// 	
// 	public Node(Node n) {
// 		init(n.id, n.px, n.py, n.x, n.y);
// 	}
// 	
// 	private void init(int _id, double _px, double _py, double _x, double _y) {
// 		this.id = _id;
// 		this.px = _px;
// 		this.py = _py;
// 		this.x = _x;
// 		this.y = _y;
// 	}
// 	
// 	public int getId() {
// 		return id;
// 	}
// 	
// 	public double getPx() {
// 		return px;
// 	}
// 	
// 	public double getPy() {
// 		return py;
// 	}
// 	
// 	public double getX() {
// 		return x;
// 	}
// 	
// 	public double getY() {
// 		return y;
// 	}
// 	
// 	public double euclideanDistance(Node b) {
// 		return Math.sqrt( Math.pow(x - b.getX(),2) + Math.pow(y - b.getY(),2));
// 	}
// 	
// 	public double euclideanDistance(double posX, double posY) {
// 		return euclideanDistance(new Node(0, 0, 0, posX, posY));
// 	}
// 
// }
// 
// Path: NavigationDG/src/org/dg/wifi/MyScanResult.java
// public class MyScanResult {
// 	public MyScanResult(String _BSSID, int _level) {
// 		BSSID = _BSSID;
// 		level = _level;
// 		networkName = "";
// 	}
// 	
// 	public MyScanResult(String _BSSID, int _level, String _networkName) {
// 		BSSID = _BSSID;
// 		level = _level;
// 		networkName = _networkName;
// 	}
// 	
// 	public MyScanResult(String _BSSID, int _level, String _networkName, int _frequency) {
// 		BSSID = _BSSID;
// 		level = _level;
// 		networkName = _networkName;
// 		frequency = _frequency;
// 	}
// 	
// 	
// 	public int level, frequency;	
// 	public String BSSID;
// 	public String networkName;
// }


// Path: NavigationDGWithSubmodules/OpenAIL/openAILdemo/src/main/java/org/dg/openAIL/PriorMapHandler.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Scanner;
import org.dg.main.Edge;
import org.dg.main.Node;
import org.dg.wifi.MyScanResult;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.util.Log;


	/**
	 * Checks and creates a directory for a new map
	 * 
	 * @param mapName
	 * @return
	 */
	private String creatingSaveMapDirectory(String mapName) {
		// Setting the directory of output
		String pathName = String.format(Locale.getDefault(), Environment
				.getExternalStorageDirectory().toString()
				+ "/OpenAIL/PriorData/" + mapName + "/");

		// Create directory if it doesn't exist
		File folder = new File(pathName);
		if (!folder.exists()) {
			folder.mkdir();
		}
		return pathName;
	}

	/**
	 * Saves the provided image in a map-compatible format
	 * 
	 * @param image
	 * @param pathName
	 */
	private void saveImageOfMapPoint(int mapPointId, Mat image, String pathName) {
		// Creating directory if needed
		File folder = new File(pathName + "images/");
		if (!folder.exists()) {