sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sma...@apache.org
Subject svn commit: r1525754 [10/11] - in /sis/sandbox/gsoc2013/crimgeoprofile: ./ Documantation/ css/ jquery/css/ jquery/css/ui-lightness/ jquery/js/ js/
Date Tue, 24 Sep 2013 00:12:23 GMT
Modified: sis/sandbox/gsoc2013/crimgeoprofile/js/Icon.Label.Default.js
URL: http://svn.apache.org/viewvc/sis/sandbox/gsoc2013/crimgeoprofile/js/Icon.Label.Default.js?rev=1525754&r1=1525753&r2=1525754&view=diff
==============================================================================
--- sis/sandbox/gsoc2013/crimgeoprofile/js/Icon.Label.Default.js (original)
+++ sis/sandbox/gsoc2013/crimgeoprofile/js/Icon.Label.Default.js Tue Sep 24 00:12:22 2013
@@ -1,29 +1,29 @@
-L.Icon.Label.Default = L.Icon.Label.extend({
-	options: {
-		//This is the top left position of the label within the wrapper. By default it will display at the right
-		//middle position of the default icon. x = width of icon + padding
-		//If the icon height is greater than the label height you will need to set the y value.
-		//y = (icon height - label height) / 2
-		labelAnchor: new L.Point(29, 8),
-		
-		//This is the position of the wrapper div. Use this to position icon + label relative to the Lat/Lng.
-		//By default the point of the default icon is anchor
-		wrapperAnchor: new L.Point(13, 41),
-		
-		//This is now the top left position of the icon within the wrapper.
-		//If the label height is greater than the icon you will need to set the y value.
-		//y = (label height - icon height) / 2
-		iconAnchor: new L.Point(0, 0),
-		
-		//label's text component, if this is null the element will not be created
-		labelText: null,
-		
-		/* From L.Icon.Default */
-		iconUrl: L.Icon.Default.imagePath + '/marker-icon.png',
-		iconSize: new L.Point(25, 41),
-		popupAnchor: new L.Point(0, -33),
-
-		shadowUrl: L.Icon.Default.imagePath + '/marker-shadow.png',
-		shadowSize: new L.Point(41, 41)
-	}
+L.Icon.Label.Default = L.Icon.Label.extend({
+	options: {
+		//This is the top left position of the label within the wrapper. By default it will display at the right
+		//middle position of the default icon. x = width of icon + padding
+		//If the icon height is greater than the label height you will need to set the y value.
+		//y = (icon height - label height) / 2
+		labelAnchor: new L.Point(29, 8),
+		
+		//This is the position of the wrapper div. Use this to position icon + label relative to the Lat/Lng.
+		//By default the point of the default icon is anchor
+		wrapperAnchor: new L.Point(13, 41),
+		
+		//This is now the top left position of the icon within the wrapper.
+		//If the label height is greater than the icon you will need to set the y value.
+		//y = (label height - icon height) / 2
+		iconAnchor: new L.Point(0, 0),
+		
+		//label's text component, if this is null the element will not be created
+		labelText: null,
+		
+		/* From L.Icon.Default */
+		iconUrl: L.Icon.Default.imagePath + '/marker-icon.png',
+		iconSize: new L.Point(25, 41),
+		popupAnchor: new L.Point(0, -33),
+
+		shadowUrl: L.Icon.Default.imagePath + '/marker-shadow.png',
+		shadowSize: new L.Point(41, 41)
+	}
 });
\ No newline at end of file

Modified: sis/sandbox/gsoc2013/crimgeoprofile/js/Icon.Label.js
URL: http://svn.apache.org/viewvc/sis/sandbox/gsoc2013/crimgeoprofile/js/Icon.Label.js?rev=1525754&r1=1525753&r2=1525754&view=diff
==============================================================================
--- sis/sandbox/gsoc2013/crimgeoprofile/js/Icon.Label.js (original)
+++ sis/sandbox/gsoc2013/crimgeoprofile/js/Icon.Label.js Tue Sep 24 00:12:22 2013
@@ -1,111 +1,111 @@
-L.Icon.Label = L.Icon.extend({
-	options: {
-		/*
-		labelAnchor: (Point) (top left position of the label within the wrapper, default is right)
-		wrapperAnchor: (Point) (position of icon and label relative to Lat/Lng)
-		iconAnchor: (Point) (top left position of icon within wrapper)
-		labelText: (String) (label's text component, if this is null the element will not be created)
-		*/
-		/* Icon options:
-		iconUrl: (String) (required)
-		iconSize: (Point) (can be set through CSS)
-		iconAnchor: (Point) (centered by default if size is specified, can be set in CSS with negative margins)
-		popupAnchor: (Point) (if not specified, popup opens in the anchor point)
-		shadowUrl: (Point) (no shadow by default)
-		shadowSize: (Point)
-		*/
-		labelClassName: ''
-	},
-	
-	initialize: function (options) {
-		L.Util.setOptions(this, options);
-		L.Icon.prototype.initialize.call(this, this.options);
-	},
-
-	setLabelAsHidden: function () {
-		this._labelHidden = true;
-	},
-
-	createIcon: function () {
-		return this._createLabel(L.Icon.prototype.createIcon.call(this));
-	},
-	
-	createShadow: function () {
-		if (!this.options.shadowUrl) {
-			return null;
-		}
-		var shadow = L.Icon.prototype.createShadow.call(this);
-		//need to reposition the shadow
-		if (shadow) {
-			shadow.style.marginLeft = (-this.options.wrapperAnchor.x) + 'px';
-			shadow.style.marginTop = (-this.options.wrapperAnchor.y) + 'px';
-		}
-		return shadow;
-	},
-
-	updateLabel: function (icon, text) {
-		if (icon.nodeName.toUpperCase() === 'DIV') {
-			icon.childNodes[1].innerHTML = text;
-			
-			this.options.labelText = text;
-		}
-	},
-
-	showLabel: function (icon) {
-		if (!this._labelTextIsSet()) {
-			return;
-		}
-
-		icon.childNodes[1].style.display = 'block';
-	},
-
-	hideLabel: function (icon) {
-		if (!this._labelTextIsSet()) {
-			return;
-		}
-
-		icon.childNodes[1].style.display = 'none';
-	},
-
-	_createLabel: function (img) {
-		if (!this._labelTextIsSet()) {
-			return img;
-		}
-
-		var wrapper = document.createElement('div'),
-			label = document.createElement('span');
-
-		// set up wrapper anchor
-		wrapper.style.marginLeft = (-this.options.wrapperAnchor.x) + 'px';
-		wrapper.style.marginTop = (-this.options.wrapperAnchor.y) + 'px';
-
-		wrapper.className = 'leaflet-marker-icon-wrapper leaflet-zoom-animated';
-
-		// set up label
-		label.className = 'leaflet-marker-iconlabel ' + this.options.labelClassName;
-
-		label.innerHTML = this.options.labelText;
-
-		label.style.marginLeft = this.options.labelAnchor.x + 'px';
-		label.style.marginTop = this.options.labelAnchor.y + 'px';
-
-		if (this._labelHidden) {
-			label.style.display = 'none';
-			// Ensure that the pointer cursor shows
-			img.style.cursor = 'pointer';
-		}
-		
-		//reset icons margins (as super makes them -ve)
-		img.style.marginLeft = this.options.iconAnchor.x + 'px';
-		img.style.marginTop = this.options.iconAnchor.y + 'px';
-		
-		wrapper.appendChild(img);
-		wrapper.appendChild(label);
-
-		return wrapper;
-	},
-	
-	_labelTextIsSet: function () {
-		return typeof this.options.labelText !== 'undefined' && this.options.labelText !== null;
-	}
+L.Icon.Label = L.Icon.extend({
+	options: {
+		/*
+		labelAnchor: (Point) (top left position of the label within the wrapper, default is right)
+		wrapperAnchor: (Point) (position of icon and label relative to Lat/Lng)
+		iconAnchor: (Point) (top left position of icon within wrapper)
+		labelText: (String) (label's text component, if this is null the element will not be created)
+		*/
+		/* Icon options:
+		iconUrl: (String) (required)
+		iconSize: (Point) (can be set through CSS)
+		iconAnchor: (Point) (centered by default if size is specified, can be set in CSS with negative margins)
+		popupAnchor: (Point) (if not specified, popup opens in the anchor point)
+		shadowUrl: (Point) (no shadow by default)
+		shadowSize: (Point)
+		*/
+		labelClassName: ''
+	},
+	
+	initialize: function (options) {
+		L.Util.setOptions(this, options);
+		L.Icon.prototype.initialize.call(this, this.options);
+	},
+
+	setLabelAsHidden: function () {
+		this._labelHidden = true;
+	},
+
+	createIcon: function () {
+		return this._createLabel(L.Icon.prototype.createIcon.call(this));
+	},
+	
+	createShadow: function () {
+		if (!this.options.shadowUrl) {
+			return null;
+		}
+		var shadow = L.Icon.prototype.createShadow.call(this);
+		//need to reposition the shadow
+		if (shadow) {
+			shadow.style.marginLeft = (-this.options.wrapperAnchor.x) + 'px';
+			shadow.style.marginTop = (-this.options.wrapperAnchor.y) + 'px';
+		}
+		return shadow;
+	},
+
+	updateLabel: function (icon, text) {
+		if (icon.nodeName.toUpperCase() === 'DIV') {
+			icon.childNodes[1].innerHTML = text;
+			
+			this.options.labelText = text;
+		}
+	},
+
+	showLabel: function (icon) {
+		if (!this._labelTextIsSet()) {
+			return;
+		}
+
+		icon.childNodes[1].style.display = 'block';
+	},
+
+	hideLabel: function (icon) {
+		if (!this._labelTextIsSet()) {
+			return;
+		}
+
+		icon.childNodes[1].style.display = 'none';
+	},
+
+	_createLabel: function (img) {
+		if (!this._labelTextIsSet()) {
+			return img;
+		}
+
+		var wrapper = document.createElement('div'),
+			label = document.createElement('span');
+
+		// set up wrapper anchor
+		wrapper.style.marginLeft = (-this.options.wrapperAnchor.x) + 'px';
+		wrapper.style.marginTop = (-this.options.wrapperAnchor.y) + 'px';
+
+		wrapper.className = 'leaflet-marker-icon-wrapper leaflet-zoom-animated';
+
+		// set up label
+		label.className = 'leaflet-marker-iconlabel ' + this.options.labelClassName;
+
+		label.innerHTML = this.options.labelText;
+
+		label.style.marginLeft = this.options.labelAnchor.x + 'px';
+		label.style.marginTop = this.options.labelAnchor.y + 'px';
+
+		if (this._labelHidden) {
+			label.style.display = 'none';
+			// Ensure that the pointer cursor shows
+			img.style.cursor = 'pointer';
+		}
+		
+		//reset icons margins (as super makes them -ve)
+		img.style.marginLeft = this.options.iconAnchor.x + 'px';
+		img.style.marginTop = this.options.iconAnchor.y + 'px';
+		
+		wrapper.appendChild(img);
+		wrapper.appendChild(label);
+
+		return wrapper;
+	},
+	
+	_labelTextIsSet: function () {
+		return typeof this.options.labelText !== 'undefined' && this.options.labelText !== null;
+	}
 });
\ No newline at end of file

Modified: sis/sandbox/gsoc2013/crimgeoprofile/js/Marker.Label.js
URL: http://svn.apache.org/viewvc/sis/sandbox/gsoc2013/crimgeoprofile/js/Marker.Label.js?rev=1525754&r1=1525753&r2=1525754&view=diff
==============================================================================
--- sis/sandbox/gsoc2013/crimgeoprofile/js/Marker.Label.js (original)
+++ sis/sandbox/gsoc2013/crimgeoprofile/js/Marker.Label.js Tue Sep 24 00:12:22 2013
@@ -1,48 +1,48 @@
-L.Marker.Label = L.Marker.extend({
-	updateLabel: function (text) {
-		this.options.icon.updateLabel(this._icon, text);
-	},
-
-	_initIcon: function () {
-		if (!(this.options.icon instanceof L.Icon.Label)) {
-			throw new Error('Icon must be an instance of L.Icon.Label.');
-		}
-
-		// Ensure that the label is hidden to begin with
-		if (this.options.revealing) {
-			this.options.icon.setLabelAsHidden();
-		}
-
-		L.Marker.prototype._initIcon.call(this);
-	},
-
-	_removeIcon: function () {
-		if (this.options.revealing) {
-			L.DomEvent
-				.off(this._icon, 'mouseover', this._showLabel)
-				.off(this._icon, 'mouseout', this._hideLabel);
-		}
-
-		L.Marker.prototype._removeIcon.call(this);
-	},
-
-	_initInteraction: function () {
-		L.Marker.prototype._initInteraction.call(this);
-
-		if (!this.options.revealing) {
-			return;
-		}
-
-		L.DomEvent
-			.on(this._icon, 'mouseover', this._showLabel, this)
-			.on(this._icon, 'mouseout', this._hideLabel, this);
-	},
-
-	_showLabel: function () {
-		this.options.icon.showLabel(this._icon);
-	},
-
-	_hideLabel: function () {
-		this.options.icon.hideLabel(this._icon);
-	}
+L.Marker.Label = L.Marker.extend({
+	updateLabel: function (text) {
+		this.options.icon.updateLabel(this._icon, text);
+	},
+
+	_initIcon: function () {
+		if (!(this.options.icon instanceof L.Icon.Label)) {
+			throw new Error('Icon must be an instance of L.Icon.Label.');
+		}
+
+		// Ensure that the label is hidden to begin with
+		if (this.options.revealing) {
+			this.options.icon.setLabelAsHidden();
+		}
+
+		L.Marker.prototype._initIcon.call(this);
+	},
+
+	_removeIcon: function () {
+		if (this.options.revealing) {
+			L.DomEvent
+				.off(this._icon, 'mouseover', this._showLabel)
+				.off(this._icon, 'mouseout', this._hideLabel);
+		}
+
+		L.Marker.prototype._removeIcon.call(this);
+	},
+
+	_initInteraction: function () {
+		L.Marker.prototype._initInteraction.call(this);
+
+		if (!this.options.revealing) {
+			return;
+		}
+
+		L.DomEvent
+			.on(this._icon, 'mouseover', this._showLabel, this)
+			.on(this._icon, 'mouseout', this._hideLabel, this);
+	},
+
+	_showLabel: function () {
+		this.options.icon.showLabel(this._icon);
+	},
+
+	_hideLabel: function () {
+		this.options.icon.hideLabel(this._icon);
+	}
 });
\ No newline at end of file

Modified: sis/sandbox/gsoc2013/crimgeoprofile/js/functions.js
URL: http://svn.apache.org/viewvc/sis/sandbox/gsoc2013/crimgeoprofile/js/functions.js?rev=1525754&r1=1525753&r2=1525754&view=diff
==============================================================================
--- sis/sandbox/gsoc2013/crimgeoprofile/js/functions.js (original)
+++ sis/sandbox/gsoc2013/crimgeoprofile/js/functions.js Tue Sep 24 00:12:22 2013
@@ -1,122 +1,140 @@
+//The following fucntion iniializes the object and other variables
 function init(){	
-	findroutes = 0;
-	first = 0;	
-	data_obj = new Object();		
-	data_obj.locations=new Array();		
-	data_obj.homeid = 0;	
-	data_obj.officeid = 0;	
-	data_obj.lunchaid = 0;	
-	data_obj.lunchbid = 0;
-	data_obj.barid = 0;
-	data_obj.mallid = 0;		
-	data_obj.sch_sl = new Array();
-	data_obj.sch_el = new Array();
-	data_obj.sch_t = new Array();
-	data_obj.sch_type = new Array();
-	data_obj.sch_len = 0;
-	data_obj.loc_num = 0;
-	data_obj.sch_init = 0;
-	
-	data_obj.crime_spot = new Array();
-	crime_spot_markers = new Array();
-	data_obj.crime_reward = new Array();
-	data_obj.crime_risk = new Array();
-	data_obj.crime_freq = new Array();
+	findroutes = 0;	//whether beeline route times have been caluclated: 0 for No, 1 for 
+	first_sim == 0;	//whether simulation week of simualtion has been completed for routine activity
+	first = 0;	//Whether its the first time routine activity is being simulated
+	data_obj = new Object();	//creating object
+	data_obj.locations=new Array();		//stores locations marked
+	data_obj.homeid = -1;	//ID for Home
+	data_obj.officeid = -1;		//ID for Office
+	data_obj.lunchaid = -1;		//ID for Lunch-A	
+	data_obj.lunchbid = -1;		//ID for Lunch-B
+	data_obj.barid = -1;	//ID for Bar
+	data_obj.mallid = -1;	//ID for Mall
+	
+	data_obj.crime_spot = new Array();	//Stores Crime Spots
+	crime_spot_markers = new Array();	//Stores MArkers for Crime Spots
+	data_obj.crime_reward = new Array();	//stores profit associated with Crime Spots
+	data_obj.crime_risk = new Array();	//stores Inherent Risk associated with Crime Spots
+	data_obj.crime_freq = new Array();	//stores the numebr of times a crime spot has been visited
 	data_obj.pp = new Array();  //prob that patrolling police is present in vicinity
 	data_obj.gd = new Array();  //prob that guardian is away
-	data_obj.num_crime_spot = 0;
-	data_obj.num_ajax = 0;
-	data_obj.num_ajax_counter = 0;
-	
-	data_obj.routes=[];
-	
-	data_obj.num_locations=0;
-	data_obj.city_lat = 51.505, 21;
-	data_obj.city_lon = 21;
-	data_obj.zoom=1;
-	
-	data_obj.risk_avoidance = Math.random();
-	data_obj.profit_seeking = Math.random();
-	data_obj.maxprofitpossible = 100;
-	data_obj.maxriskpresent = 100;
+	data_obj.routes=[];		//stores routes taken by the agent
+
+	//miscelleneous variables
+	data_obj.num_locations = 0;		//stores number of locations marked
+	data_obj.sch_sl = new Array();	//stores the statring locations in the schedule
+	data_obj.sch_el = new Array();	//stores end locations in the schedule
+	data_obj.sch_t = new Array();	//stores the time avaialable for various routes int eh schedule
+	data_obj.sch_type = new Array();	//stores the type of motion to take in the schedule - 1:Beeline, 2:Rnadom, 3: Hybrid
+	data_obj.sch_len = 0;	//stores the number of routes in the schedule
+	data_obj.sch_init = 0;	//whether the schedule has been initialized
+	data_obj.num_crime_spot = 0;	//stores the numebr of crime spots marked
+	data_obj.num_ajax = 0;	//stores the number of ajax calls to be made to simualte a week of the schedule
+	data_obj.num_ajax_counter = 0;	//stores the numebr of ajax calls made so far
+	ddcount = 0;	//If ajax calls are being made for simulating distance decay
+	data_obj.city_lat = 39.7683795; 	//laititude of city
+	data_obj.city_lon = -86.1580447;		//longitude of city
+	data_obj.zoom=12;	//zoom level of map	
+	
+	//global variables
+	data_obj.risk_avoidance = Math.random();	//random value between 0 and 1
+	data_obj.profit_seeking = Math.random();	//random value between 0 and 1
+	data_obj.maxprofitpossible = 100;		//maximum reward that can be associated with a crime spot
+	data_obj.maxriskpresent = 100;		//maximum inherent risk that can be associated with a crime spot
 	
 }
 
+//The following function marks Home on the map
 function markHome(e){	
 	var marker=L.marker(e.latlng, { icon: new L.Icon.Label.Default({ labelText: "Home" }) }).addTo(map);	
-	//data_obj.home[data_obj.num_home++]=e.latlng;
+	//store data in object
 	data_obj.homeid=data_obj.num_locations;	
-	data_obj.locations[data_obj.num_locations++]=e.latlng;		
+	data_obj.locations[data_obj.num_locations++]=e.latlng;	
+	//disable marking any more Home
 	map.off('click', markHome);
-	$('#addhome').attr("disabled", "disabled");
-	data_obj.loc_num++;
+	$('#addhome').attr("disabled", "disabled");	
 }
 
+//The following function marks Office on the map
 function markOffice(e){
 	var marker=L.marker(e.latlng, { icon: new L.Icon.Label.Default({ labelText: "Office" }) }).addTo(map);	
-	//data_obj.office[data_obj.num_office++]=e.latlng;	
+	//store data in object
 	data_obj.officeid=data_obj.num_locations;
-	data_obj.locations[data_obj.num_locations++]=e.latlng;	
+	data_obj.locations[data_obj.num_locations++]=e.latlng;
+	//disable marking any more Office
 	map.off('click', markOffice);
-	$('#addoffice').attr("disabled", "disabled");
-	data_obj.loc_num++;
+	$('#addoffice').attr("disabled", "disabled");	
 }
 
+//The following function marks Bar on the map
 function markBar(e){
 	var marker=L.marker(e.latlng, { icon: new L.Icon.Label.Default({ labelText: "Bar" }) }).addTo(map);	
-	//data_obj.hangout[data_obj.num_hangout++]=e.latlng;
+	//store data in object
 	data_obj.barid=data_obj.num_locations;	
 	data_obj.locations[data_obj.num_locations++]=e.latlng;	
+	//disable marking any more Bar
 	map.off('click', markBar);
-	$('#addbar').attr("disabled", "disabled");
-	data_obj.loc_num++;
+	$('#addbar').attr("disabled", "disabled");	
 }
 
+//The following function marks Lunch-A on the map
 function markLunchA(e){
 	var marker=L.marker(e.latlng, { icon: new L.Icon.Label.Default({ labelText: "Lunch-A" }) }).addTo(map);
+	//store data in object
 	data_obj.lunchaid=data_obj.num_locations;
 	data_obj.locations[data_obj.num_locations++]=e.latlng;	
+	//disable marking any more Lunch-A
 	map.off('click', markLunchA);
-	$('#addluncha').attr("disabled", "disabled");
-	data_obj.loc_num++;
+	$('#addluncha').attr("disabled", "disabled");	
 }
 
+//The following function marks Lunch-B on the map
 function markLunchB(e){
 	var marker=L.marker(e.latlng, { icon: new L.Icon.Label.Default({ labelText: "Lunch-B" }) }).addTo(map);
+	//store data in object
 	data_obj.lunchbid=data_obj.num_locations;
 	data_obj.locations[data_obj.num_locations++]=e.latlng;	
+	//disable marking any more Lunch-B
 	map.off('click', markLunchB);
-	$('#addlunchb').attr("disabled", "disabled");
-	data_obj.loc_num++;
+	$('#addlunchb').attr("disabled", "disabled");	
 }
 
+//The following function marks Mall on the map
 function markMall(e){
 	var marker=L.marker(e.latlng, { icon: new L.Icon.Label.Default({ labelText: "Mall" }) }).addTo(map);
+	//store data in object
 	data_obj.mallid=data_obj.num_locations;
 	data_obj.locations[data_obj.num_locations++]=e.latlng;	
+	//disable marking any more Mall
 	map.off('click', markMall);
-	$('#addmall').attr("disabled", "disabled");
-	data_obj.loc_num++;
+	$('#addmall').attr("disabled", "disabled");	
 }
 
+//The following function marks a Crime Spot on the map
 function markCrimeSpot(e){	
-	var rd = Math.random()*data_obj.maxprofitpossible;
-	var rs = Math.random()*data_obj.maxriskpresent;
-	var pp = Math.random();
-	var gd = Math.random();
-	data_obj.crime_freq[data_obj.num_crime_spot]=0;
-	var marker=L.marker(e.latlng, { icon: new L.Icon.Label.Default({ labelText: "CS-" + (data_obj.num_crime_spot+1) + " ["+Math.floor(rd)+", "+Math.floor(rs)+", "+Math.floor(pp*100)/100+", "+Math.floor(gd*100)/100+", 0]"}) }).addTo(map);	
+	var rd = Math.random()*data_obj.maxprofitpossible;	//reward
+	var rs = Math.random()*data_obj.maxriskpresent;		//risk
+	var pp = Math.random();		//probability that police is in vicinity of this spot
+	var gd = Math.random();		//probability that guardian of the spot i.e. the victim agent is away
+	data_obj.crime_freq[data_obj.num_crime_spot]=0;		//number of times the spot has been visited by the criminal agent
+	//storing data in the object
 	crime_spot_markers[data_obj.num_crime_spot]=marker;
 	data_obj.crime_risk[data_obj.num_crime_spot]=rs;
 	data_obj.crime_reward[data_obj.num_crime_spot]=rd;
 	data_obj.pp[data_obj.num_crime_spot] = pp;
 	data_obj.gd[data_obj.num_crime_spot] = gd;
-	data_obj.crime_spot[data_obj.num_crime_spot]=e.latlng;	
-	data_obj.num_crime_spot++;
+	data_obj.crime_spot[data_obj.num_crime_spot]=e.latlng;			//Latitude-Longitude of Crime Spot
+	//data t be shown on popuu
+	var popup = "["+Math.floor(rd)+", "+Math.floor(rs)+", "+Math.floor(pp*100)/100+", "+Math.floor(gd*100)/100+"]";
+	//adding marker to map with popup
+	var marker=L.marker(e.latlng, { icon: new L.Icon.Label.Default({ labelText: "CS-" + (data_obj.num_crime_spot+1) + " [0]"}) }).addTo(map).bindPopup(popup);
+	crime_spot_markers[data_obj.num_crime_spot] = marker;	//stroing marker
+	data_obj.num_crime_spot++;	
 	map.off('click', markCrimeSpot);	
 }
 
-
+//The following function is used to add scripts for making get calls
 function addScript(url) {
 	var script = document.createElement('script');
 	script.type="text/javascript";
@@ -124,6 +142,7 @@ function addScript(url) {
 	document.getElementsByTagName('head') [0].appendChild(script);
 }
 
+//The following fucntions adds new functions to the code
 function addFunc(code){	
 	var script = document.createElement('script');
 	script.type="text/javascript";
@@ -131,66 +150,92 @@ function addFunc(code){	
 	document.getElementsByTagName('head') [0].appendChild(script);
 }
 
-
+//The following fucntion gets the latitude and longitude of a city
 function getLatLon(response){
 	var lat=response[0]["lat"];
 	var lon=response[0]["lon"];	
 	data_obj.city_lat = lat;
 	data_obj.city_lon = lon;
-	data_obj.zoom=14;
+	data_obj.zoom=12;
 	map.setView([lat, lon], 14);
 }
-           
+
+//The following function is used to find the route for the agent to go back home, when the simualtion is about to stop in distance decay
+function goHome(response){
+	var rand_path = response;						
+	var pt, pts = [];
+	//stroing route points in array
+	for (var i=0; i<rand_path.route_geometry.length; i++){					
+		pt = new L.LatLng(rand_path.route_geometry[i][0] , rand_path.route_geometry[i][1]);						
+		pts.push(pt);
+	}
+	data_obj.routes.push(pts);
+	//calcaulating distance
+	dist = dist + (rand_path.route_summary['total_distance']/1000);
+	//marking polylines on map corresponding to the route
+	route= new L.Polyline(pts, {
+		weight: 5,
+		opacity: 0.2,
+		color: 'blue',
+		smoothFactor: 1
+	}).addTo(map);
+	route.bringToFront();	
+}
+       
+//Finding and Storing routes between all possible pair of locations	   
 function showRoutes(){
 	findroutes = 1;
-	//alert("Finding and Storing routes between all possible pair of locations. You will be alerted when we are done. Please wait till then.");
+	//alert("Finding and Storing routes between all possible pair of locations. You will be alerted when we are done. Please wait till then.");	
+	//creating 2d array to store the first path between all possible pair of locations
 	data_obj.path1 = new Array(data_obj.num_locations);
 	for(var i=0; i < data_obj.num_locations; i++){
 		data_obj.path1[i] = new Array(data_obj.num_locations);
 	}
+	//creating 2d array to store the second path between all possible pair of locations
 	data_obj.path2 = new Array(data_obj.num_locations);
 	for(var i=0; i < data_obj.num_locations; i++){
 		data_obj.path2[i] = new Array(data_obj.num_locations);
 	}
+	//creating 2d array to store the third path between all possible pair of locations
 	data_obj.path3 = new Array(data_obj.num_locations);
 	for(var i=0; i < data_obj.num_locations; i++){
 		data_obj.path3[i] = new Array(data_obj.num_locations);
 	}
-		
+	//creating 2d array to store the time required to traverse the first path between all possible pair of locations	
 	data_obj.time1 = new Array(data_obj.num_locations);
 	for(var i=0; i < data_obj.num_locations; i++){
 		data_obj.time1[i] = new Array(data_obj.num_locations);
 	}
+	//creating 2d array to store the time required to traverse the second path between all possible pair of locations
 	data_obj.time2 = new Array(data_obj.num_locations);
 	for(var i=0; i < data_obj.num_locations; i++){
 		data_obj.time2[i] = new Array(data_obj.num_locations);
 	}
+	//creating 2d array to store the time required to traverse the third path between all possible pair of locations
 	data_obj.time3 = new Array(data_obj.num_locations);
 	for(var i=0; i < data_obj.num_locations; i++){
 		data_obj.time3[i] = new Array(data_obj.num_locations);
 	}
-	
+	//creating 2d array to store the distance of the first path between all possible pair of locations
 	data_obj.dist1 = new Array(data_obj.num_locations);
 	for(var i=0; i < data_obj.num_locations; i++){
 		data_obj.dist1[i] = new Array(data_obj.num_locations);
 	}
+	//creating 2d array to store the distance of the second path between all possible pair of locations
 	data_obj.dist2 = new Array(data_obj.num_locations);
 	for(var i=0; i < data_obj.num_locations; i++){
 		data_obj.dist2[i] = new Array(data_obj.num_locations);
 	}
+	//creating 2d array to store the distance of the third path between all possible pair of locations
 	data_obj.dist3 = new Array(data_obj.num_locations);
 	for(var i=0; i < data_obj.num_locations; i++){
 		data_obj.dist3[i] = new Array(data_obj.num_locations);
 	}
 	
-	index=0;
-	var idx1=0;
-	var idx2=0;
-	var idx3=0;
-	var idx4=0;	
+	//Finding the first path between all possible pair of lcoations, along with the time and distance
 	for(var i=0;i<data_obj.num_locations-1;i++){		
 		for(var j=i+1;j<data_obj.num_locations;j++){			
-			//route1
+			//tmp contains definition of the function that extracts the first path, time and distance recieved for the first path	
 			var tmp = "function getRoute"+i+j+"1(response){"+
 				"done=0;"+
 				"var point, route, points = [];"+
@@ -204,19 +249,13 @@ function showRoutes(){
 				"data_obj.time1["+i+"]["+j+"] = response.route_summary['total_distance']*6.8/60;"+
 				"data_obj.time1["+j+"]["+i+"] = response.route_summary['total_distance']*6.8/60;"+
 				"data_obj.dist1["+i+"]["+j+"] = response.route_summary['total_distance'];"+
-				"data_obj.dist1["+j+"]["+i+"] = response.route_summary['total_distance'];"+	
-			/*	"route= new L.Polyline(points, {"+
-					"weight: 3,"+
-					"opacity: 0.5,"+
-					"color: 'blue',"+
-					"smoothFactor: 1"+
-				"}).addTo(map);"+
-				"route.bringToFront();"+*/
+				"data_obj.dist1["+j+"]["+i+"] = response.route_summary['total_distance'];"+				
 			"}";		
-			addFunc(tmp);			
+			addFunc(tmp);		//adding the function that extracts the path, time and distance recieved for the first path	
+			//finding the first path
 			addScript('http://routes.cloudmade.com/81aa79a9504e4430a8a32f491ef96f07/api/0.3/' + data_obj.locations[i].lat + ',' + data_obj.locations[i].lng + ',' + data_obj.locations[j].lat + ',' + data_obj.locations[j].lng + '/car/shortest.js?callback=getRoute'+i+j+'1');	
 			
-			//route2
+			//tmp contains definition of the function that extracts the path, time and distance recieved for the second path	
 			tmp = "function getRoute"+i+j+"2(response){"+
 				"done=0;"+
 				"var point, route, points = [];"+
@@ -231,19 +270,13 @@ function showRoutes(){
 				"data_obj.time2["+j+"]["+i+"] = response.route_summary['total_distance']*6.8/60;"+
 				"data_obj.dist2["+i+"]["+j+"] = response.route_summary['total_distance'];"+
 				"data_obj.dist2["+j+"]["+i+"] = response.route_summary['total_distance'];"+				
-			/*	"route= new L.Polyline(points, {"+
-					"weight: 3,"+
-					"opacity: 0.5,"+
-					"color: 'blue',"+
-					"smoothFactor: 1"+
-				"}).addTo(map);"+
-				"route.bringToFront();"+	*/		
 			"}";		
-			addFunc(tmp);
+			addFunc(tmp);		//adding the function that extracts the path, time and distance recieved for the second path	
+			//finding the second path
 			addScript('http://routes.cloudmade.com/81aa79a9504e4430a8a32f491ef96f07/api/0.3/' + data_obj.locations[i].lat + ',' + data_obj.locations[i].lng + ',' + data_obj.locations[j].lat + ',' + data_obj.locations[j].lng + '/foot.js?callback=getRoute'+i+j+'2');
 			
-			//route3
-			if(i == data_obj.num_locations-2 && j == data_obj.num_locations-1){
+			//tmp contains definition of the function that extracts the path, time and distance recieved for the third path				
+			if(i == data_obj.num_locations-2 && j == data_obj.num_locations-1){				//if this is the last path to be found
 				tmp = "function getRoute"+i+j+"3(response){"+
 					"done=0;"+
 					"var point, route, points = [];"+
@@ -259,17 +292,10 @@ function showRoutes(){
 					"data_obj.time3["+j+"]["+i+"] = response.route_summary['total_distance']*6.8/60;"+
 					"data_obj.dist3["+i+"]["+j+"] = response.route_summary['total_distance'];"+
 					"data_obj.dist3["+j+"]["+i+"] = response.route_summary['total_distance'];"+					
-					/*"route= new L.Polyline(points, {"+
-						"weight: 3,"+
-						"opacity: 0.5,"+
-						"color: 'brown',"+
-						"smoothFactor: 1"+
-					"}).addTo(map);"+
-					"route.bringToFront();"+	*/
-					"$('#loading').dialog('close');"+
+					"$('#loading').dialog('close');"+		//close dialog
 				"}";			
 			}
-			else{
+			else{		//if this is not the last path to be found
 				tmp = "function getRoute"+i+j+"3(response){"+
 				"done=0;"+
 				"var point, route, points = [];"+
@@ -284,86 +310,93 @@ function showRoutes(){
 				"data_obj.time3["+i+"]["+j+"] = response.route_summary['total_time'];"+
 				"data_obj.time3["+j+"]["+i+"] = response.route_summary['total_time'];"+
 				"data_obj.dist3["+i+"]["+j+"] = response.route_summary['total_distance'];"+
-				"data_obj.dist3["+j+"]["+i+"] = response.route_summary['total_distance'];"+
-				/*
-				"route= new L.Polyline(points, {"+
-					"weight: 3,"+
-					"opacity: 0.5,"+
-					"color: 'brown',"+
-					"smoothFactor: 1"+
-				"}).addTo(map);"+
-				"route.bringToFront();"+		*/		
+				"data_obj.dist3["+j+"]["+i+"] = response.route_summary['total_distance'];"+					
 			"}";			
 			}		
-			addFunc(tmp);
+			addFunc(tmp);	//adding the function that extracts the path, time and distance recieved for the third path
+			//finding the third path
 			addScript('http://routes.cloudmade.com/81aa79a9504e4430a8a32f491ef96f07/api/0.3/' + data_obj.locations[i].lat + ',' + data_obj.locations[i].lng + ','  + data_obj.locations[j].lat + ',' + data_obj.locations[j].lng + '/bicycle.js?callback=getRoute'+i+j+'3');			
-		//	console.log('http://routes.cloudmade.com/81aa79a9504e4430a8a32f491ef96f07/api/0.3/' + data_obj.locations[i].lat + ',' + data_obj.locations[i].lng + ',' + data_obj.transit[i][j] + data_obj.locations[j].lat + ',' + data_obj.locations[j].lng + '/bicycle.js?callback=getRoute'+i+j+'3');
 		}
 	}	
 }
 
-
+//The following function removes all amrkers and ploylines from the map
 function clearMap(){ 
 	for(i in map._layers){ 
 		if(map._layers[i]._path != undefined) {
 			try{ 
-				map.removeLayer(map._layers[i]); 
+				map.removeLayer(map._layers[i]); 		//removing layers form map
 			} catch(e){
-				//console.log("problem with " + e + map._layers[i]); 
+				console.log("problem with " + e + map._layers[i]); 
 			} 
 		} 
 	}
  }
-
-function simulateBeeline(start, end, time, last, rob){	
-	var nump = 0;
+ 
+ /*The following function simulates the Beeline Motion. Input parameters to the function are start location, end location, time available, and whether or not to make an attempt to commit crime in this path. Based on the direct paths to choose given the time constraint, one is chosed at random 
+ */ 
+function simulateBeeline(start, end, time, rob){	
+	var nump = 0;		//number of paths to choose from
+	//finding value of nump
 	if(time >= data_obj.time3[start][end])nump=3;
 	else if(time >= data_obj.time2[start][end])nump=2;
 	else if(time >= data_obj.time1[start][end])nump=1;	
+	//choosing a path at random from the available paths
 	var num = Math.floor((Math.random()*nump)+1);
-	if(num == 1){
-		var ar =data_obj.path1[start][end];
-		
+	//making the agent  move on the chosen path
+	if(num == 1){		//first path is chosen
+		var ar =data_obj.path1[start][end];		//getting the first path
+	    //marking Polylines for the first path
 		var route= new L.Polyline(data_obj.path1[start][end], {
 			weight: 5,
 			opacity: 0.2,
 			color: 'blue',
 			smoothFactor: 1
 		}).addTo(map);
-		route.bringToFront();
+		route.bringToFront();	
+	    //Calling the memory function which remembers the spots visited and makes (or does not make) an attempt to commit crime based on value of rob		
 		markVisited(data_obj.path1[start][end], rob);
+		//adding this route to the set of routes
 		data_obj.routes.push(data_obj.path1[start][end]);
 	}
-	else if(num ==2){
-		var route= new L.Polyline(data_obj.path2[start][end], {
+	else if(num ==2){	//second path is chosen
+		//marking Polylines for the second path
+		var route= new L.Polyline(data_obj.path2[start][end], {				//getting the second path
 			weight: 5,
 			opacity: 0.2,
 			color: 'blue',
 			smoothFactor: 1
 		}).addTo(map);
 		route.bringToFront();
+		//Calling the memory function which remembers the spots visited and makes (or does not make) an attempt to commit crime based on value of rob	
 		markVisited(data_obj.path1[start][end], rob);
+		//adding this route to the set of routes
 		data_obj.routes.push(data_obj.path2[start][end]);
 	}
-	else if(num ==3){
-		var route= new L.Polyline(data_obj.path3[start][end], {
+	else if(num ==3){	//third path is chosen
+		//marking Polylines for the third path
+		var route= new L.Polyline(data_obj.path3[start][end], {				//getting the third path
 			weight: 5,
 			opacity: 0.2,
 			color: 'blue',
 			smoothFactor: 1
 		}).addTo(map);
 		route.bringToFront();
+		//Calling the memory function which remembers the spots visited and makes (or does not make) an attempt to commit crime based on value of rob	
 		markVisited(data_obj.path1[start][end], rob);
+		//adding this route to the set of routes
 		data_obj.routes.push(data_obj.path3[start][end]);
 	}	
 }
 
+/*The following function simulates the Random Motion. Input parameters to the function are start location, end location, time available, and whether or not to make an attempt to commit crime in this path. The agent starts form the given location and at each intersection, choses a path at random, untill time runs out, when the agent takes the shortest path to the destination. This is implementd by calling a server side script - "routing.php" 
+ */ 
 function simulateRandom(start, end, time,last, rob ){
-	var start_lat = data_obj.locations[start].lat;
-	var start_lon = data_obj.locations[start].lng;
-	var end_lat = data_obj.locations[end].lat;
-	var end_lon = data_obj.locations[end].lng;	
-	//console.log("Random("+start_lat+","+start_lon+","+end_lat+","+end_lon+","+time+")");
+	var start_lat = data_obj.locations[start].lat;		//Latitude of Start Location
+	var start_lon = data_obj.locations[start].lng;		//Longitude of Start Location
+	var end_lat = data_obj.locations[end].lat;		//Latitude of End Location
+	var end_lon = data_obj.locations[end].lng;		//Longitude of Start Location	
+	//making ajax request to the server side script
 	var randomsim = $.ajax({
 		type: "POST",
 		url: "routing.php",		   
@@ -374,15 +407,23 @@ function simulateRandom(start, end, time
 			end_lon : end_lon ,
 			time : time				
 		},		
-		success: function(data){	
-                        ajaxComplete();
+		success: function(data){
+			if(ddcount >= 1){		//If the simulation is for Distance Decay
+				ddCounter();	//Call the function to track the number of ajax calls that have returned response	
+			}
+			else{	//If the simulation is for Routine Activity
+				ajaxComplete();		//Call the function to track the number of ajax calls that have returned response
+			}
 			var rand_path = data;			
 			var pt, pts = [];
+			//Extracting Points on the Route
 			for (var i=0; i<rand_path.route_geometry.length; i++){					
 				pt = new L.LatLng(rand_path.route_geometry[i][0] , rand_path.route_geometry[i][1]);						
 				pts.push(pt);
 			}
+			//adding this route to the set of routes
 			data_obj.routes.push(pts);
+			//marking polylines for this route on the map
 			route= new L.Polyline(pts, {
 				weight: 5,
 				opacity: 0.2,
@@ -390,19 +431,20 @@ function simulateRandom(start, end, time
 				smoothFactor: 1
 			}).addTo(map);
 			route.bringToFront();
+			//Calling the memory function which remembers the spots visited and makes (or does not make) an attempt to commit crime based on value of rob	
 			markVisited(pts, rob);				
 		}
 	});	
-
-
 }
 
+/*The following function simulates the Hybrid Motion. Input parameters to the function are start location, end location, time available, and whether or not to make an attempt to commit crime in this path. The agent chooses two points along the shortest route at random, and goes through a longer different route between them. The agent does this again if time remains, otherwise goes to the destination via the shortest path from thereon. This is implementd by calling a server side script - "hybrid.php" 
+ */ 
 function simulateHybrid(start , end, time, last, rob){		
-	var start_lat = data_obj.locations[start].lat;
-	var start_lon = data_obj.locations[start].lng;
-	var end_lat = data_obj.locations[end].lat;
-	var end_lon = data_obj.locations[end].lng;		
-	//console.log("Hybrid("+start_lat+","+start_lon+","+end_lat+","+end_lon+","+time+")");
+	var start_lat = data_obj.locations[start].lat;	//Latitude of Start Location
+	var start_lon = data_obj.locations[start].lng;		//Longitude of Start Location
+	var end_lat = data_obj.locations[end].lat;	//Latitude of End Location
+	var end_lon = data_obj.locations[end].lng;		//Longitude of End Location		
+	//making ajax call
 	$.ajax({
 	  type: "POST",
 	  url: "hybrid.php",		   
@@ -413,15 +455,18 @@ function simulateHybrid(start , end, tim
 			end_lon : end_lon ,
 			time : time				
 		},		
-	  success: function(data){
-			ajaxComplete();	
+	  success: function(data){	
+			ajaxComplete();	//Call the function to track the number of ajax calls that have returned response
 			var obj = data;					
 			var pt, pts = [];
+			//Extracting points along the route
 			for (var i=0; i<obj.length; i++){					
 				pt = new L.LatLng(obj[i][0] , obj[i][1]);						
 				pts.push(pt);
 			}
+			//adding this route to the set of routes
 			data_obj.routes.push(pts);
+			//marking this route as polylines on the map
 			route= new L.Polyline(pts, {
 				weight: 5,
 				opacity: 0.2,
@@ -429,51 +474,62 @@ function simulateHybrid(start , end, tim
 				smoothFactor: 1
 			}).addTo(map);
 			route.bringToFront();
-			markVisited(pts, rob);
+			//Calling the memory function which remembers the spots visited and makes (or does not make) an attempt to commit crime based on value of rob	
+			markVisited(pts, rob);				
 		}
 	});
 }
 
+/*
+The following functon works as the memory function, where it remembers the the spots it has visited and the number of times the spot has been visited. It also decides whether or not to commit crime. The function takes as input the set of points along the route and a variable indicating whether or not the agent should attempt to commit crime
+*/
 function markVisited(points, rob){
-	var visited = new Array(data_obj.num_crime_spot);
+	var visited = new Array(data_obj.num_crime_spot);		//array of crime spots to indicate whether a crime spot has been visited along this route
 	for(var i=0; i<data_obj.num_crime_spot; i++){
-		visited[i]=0;
+		visited[i]=0;		//initializing each crime spot as not visited
 	}
+	//Iterating along points along the route
 	for(var i=1; i<points.length; i++){
+		//Iterating over all crime spots
 		for(var j=0; j<data_obj.num_crime_spot; j++){	
-			if(visited[j] == 1)continue;
+			if(visited[j] == 1)continue;		//Is a crime spot is already visited along this route, skip it
+			//Check if the crime spot is in the vicinity of the agent
 			if(liesWithin(data_obj.crime_spot[j], points[i-1], points[i]) == true){
-				visited[j]=1;
-				data_obj.crime_risk[j] +=  data_obj.maxriskpresent*0.02;		
-				if(rob == 1){
-					var risk = Math.random();
-					var profit = Math.random();
-					var ppp = Math.random();
-					var gw = Math.random();
-					if(ppp > data_obj.pp[j] ){
-						var rsk = data_obj.crime_risk[j];
-						if(gw < data_obj.gd[j]){
-							rsk = rsk/2;
+				visited[j]=1;		//mark the crime spot as visited
+				data_obj.crime_risk[j] +=  data_obj.maxriskpresent*0.02;		//update the risk value	
+				if(rob == 1){		//If the agent should consider commitng crime
+					var risk = Math.random();	//random value between 0 and 1
+					var profit = Math.random();	//random value between 0 and 1
+					var ppp = Math.random();	//random value between 0 and 1
+					var gw = Math.random();	//random value between 0 and 1
+					if(ppp > data_obj.pp[j] ){		//if patrolling police is not in the vicinity of the crim spot
+						var rsk = data_obj.crime_risk[j];		//risk associated 
+						if(gw < data_obj.gd[j]){		//if the victim agent i.e. the guardian of the spot is not present
+							rsk = rsk/2;	//reduce risk to half for this particular crime
 						}
+						//decide whether to commit crime based on normalized risk toatal risk
 						if(risk > (data_obj.risk_avoidance*rsk)/data_obj.maxriskpresent){
-							if(profit < (data_obj.profit_seeking*data_obj.crime_reward[j])/data_obj.maxprofitpossible){
-								data_obj.crime_freq[j]++;
+							//decide whether or not to commit crime based on nomalized profit value
+							if(profit < (data_obj.profit_seeking*data_obj.crime_reward[j])/data_obj.maxprofitpossible){  
+								data_obj.crime_freq[j]++;		//commit crime
 							}
 						}	
 					}
-				}
-							
+				}							
 			}
-		}
-		
+		}		
 	}
 }
 
+/*
+The following function checks if a crime spot lies in the vicitinty of an agent. It takes two consecutive point along the agents's route (a and b) and the crime spot, c, as input
+*/
 function liesWithin(c , a , b){	
-	var x1 = 0;
-	var y1 = 0;
-	var x2 = 0;
-	var y2 = 0;	
+	var x1 = 0;		//latitide of lower-left point
+	var y1 = 0;		//latitide of upper-right point
+	var x2 = 0;		//longitude of lower-left point
+	var y2 = 0;		//longitude of upper-right point
+	//Decidng which is lower left point and which is upper right point among a and b
 	if(a.lng < b.lng){
 		x1 = a.lat;
 		y1 = a.lng;
@@ -500,7 +556,7 @@ function liesWithin(c , a , b){	
 			y2 = a.lng;	
 		}
 	}
-	var theta=0;
+	var theta=0;		//angle made by the straight lone joining the points witht he horizontal
 	if(x1==x2){
 		theta = Math.PI/2;
 	}
@@ -508,336 +564,679 @@ function liesWithin(c , a , b){	
 		theta = Math.atan((y2-y1)/(x2-x1));
 	}
 	
+	//finding the southwest point of the bounding box
 	var sw_x = x1 - 1000*Math.sin(theta)/1852/60;
 	var sw_y = y1 + 1000*Math.cos(theta)/1852/60;
 	
+	//finding the northwest point of the bounding box
 	var ne_x = x2 + 1000*Math.sin(theta)/1852/60;
 	var ne_y = y2 - 1000*Math.cos(theta)/1852/60;
-	//console.log(sw_x, sw_y, ne_x, ne_y);
-	
+		
 	var southWest = new L.LatLng(sw_x, sw_y),
     northEast = new L.LatLng(ne_x, ne_y),	
+	//creating abounding box
     bounds = new L.LatLngBounds(southWest, northEast);
 	
-	//var rect = L.rectangle(bounds, {color: 'yellow', opacity: 0.01, weight: 0.01}).addTo(map);
-	//console.log(c, bounds.contains(c));
+	//checking if the crime spot lies in the bounding box
 	return bounds.contains(c);
 }
 
-
-
-
-// to display saved data
-function display(){
-//	window.location.href = window.location.pathname;
-	//displaying locations	
-	//alert(data_obj.locations[data_obj.homeid]);
-	var marker=L.marker(data_obj.locations[data_obj.homeid], { icon: new L.Icon.Label.Default({ labelText: "Home"}) }).addTo(map);
-	var marker=L.marker(data_obj.locations[data_obj.officeid], { icon: new L.Icon.Label.Default({ labelText: "Office"}) }).addTo(map);
-	var marker=L.marker(data_obj.locations[data_obj.lunchaid], { icon: new L.Icon.Label.Default({ labelText: "Lunch-A"}) }).addTo(map);
-	var marker=L.marker(data_obj.locations[data_obj.lunchbid], { icon: new L.Icon.Label.Default({ labelText: "Lunch-B"}) }).addTo(map);
-	var marker=L.marker(data_obj.locations[data_obj.barid], { icon: new L.Icon.Label.Default({ labelText: "Bar"}) }).addTo(map);
-	var marker=L.marker(data_obj.locations[data_obj.mallid], { icon: new L.Icon.Label.Default({ labelText: "Mall"}) }).addTo(map);		
-	//displaying routes
-	for(var i=0;i<data_obj.routes.length;i++){			
-		route= new L.Polyline(data_obj.routes[i], {
-			weight: 3,
-			opacity: 0.2,
-			color: 'blue',
-			smoothFactor: 1
-		}).addTo(map);	
-		route.bringToFront();
-	}		
-	//adding crime spots
-	for(var i=0; i<data_obj.crime_spot.length; i++){
-		var risk = data_obj.crime_risk[i];
-		var reward = data_obj.crime_reward[i];
-		var freq = data_obj.crime_freq[i];
-		var pp = data_obj.pp[i];
-		var gd = data_obj.gd[i];		
-		var marker=L.marker(data_obj.crime_spot[i], { icon: new L.Icon.Label.Default({ labelText: "CS-" + (i+1) + " ["+Math.floor(reward)+", "+Math.floor(risk)+", "+Math.floor(pp*100)/100+", "+Math.floor(gd*100)/100+", "+freq+"]"}) }).addTo(map);
-		crime_spot_markers[i]=marker;
-	}
-	map.setView([data_obj.city_lat, data_obj.city_lon], data_obj.zoom);
-}
-
+/*
+The following function computes the time available to the agent for a hybrid motion to be taken. This is used for initializing the schedule
+*/
 function findHybridTime(time){
-	var new_time = time/60;
-	if(time%60 !=0) new_time += 1;
+	//finding the ceil in terms of hours
+	var new_time = time/60 + 1;	
+	if(new_time*60 - time < 10)new_time+=0.5	
 	return new_time*60;
 }
 
-function sortTime(){
+/*
+The following function sorts the 3 beeline routes according to the time required to traverse them. THis is done for all beeline routes between all possible pair of locations. 
+*/
+function sortTime(){	
 	for(var i=0; i<data_obj.num_locations-1; i++){
 		for(var j=i+1;j<data_obj.num_locations;j++){
-			if(data_obj.time1[i][j] > data_obj.time2[i][j]){
+			if(data_obj.time1[i][j] > data_obj.time2[i][j]){		
+				//swap time
 				var tmp1 = data_obj.time1[i][j];
 				data_obj.time1[i][j] = data_obj.time2[i][j];
 				data_obj.time2[i][j] = tmp1;
-				
+				//swap distance
 				var tmp2 = data_obj.dist1[i][j];
 				data_obj.dist1[i][j] = data_obj.dist2[i][j];
 				data_obj.dist2[i][j] = tmp2;
-				
+				//swap path
 				var tmp3 = data_obj.path1[i][j];
 				data_obj.path1[i][j] = data_obj.path2[i][j];
 				data_obj.path2[i][j] = tmp3;
 			}
 			if(data_obj.time2[i][j] > data_obj.time3[i][j]){
+				//swap time
 				var tmp1 = data_obj.time2[i][j];
 				data_obj.time2[i][j] = data_obj.time3[i][j];
 				data_obj.time3[i][j] = tmp1;
-				
+				//swap distance
 				var tmp2 = data_obj.dist2[i][j];
 				data_obj.dist2[i][j] = data_obj.dist3[i][j];
 				data_obj.dist3[i][j] = tmp2;
-				
+				//swap path
 				var tmp3 = data_obj.path2[i][j];
 				data_obj.path2[i][j] = data_obj.path3[i][j];
 				data_obj.path3[i][j] = tmp3;
 			}
 			if(data_obj.time1[i][j] > data_obj.time2[i][j]){
+				//swap time
 				var tmp1 = data_obj.time1[i][j];
 				data_obj.time1[i][j] = data_obj.time2[i][j];
 				data_obj.time2[i][j] = tmp1;
-				
+				//swap distance
 				var tmp2 = data_obj.dist1[i][j];
 				data_obj.dist1[i][j] = data_obj.dist2[i][j];
 				data_obj.dist2[i][j] = tmp2;
-				
+				//swap path
 				var tmp3 = data_obj.path1[i][j];
 				data_obj.path1[i][j] = data_obj.path2[i][j];
 				data_obj.path2[i][j] = tmp3;
 			}
 		}
-	}
-	//alert(JSON.stringify(data_obj));
+	}	
 }
 				
-
+/*
+The following function initializes the agent's weekly shcedule by plugging in route times to the template of the schedule
+*/
 function initSchedule(){
 	//Monday		
-	data_obj.sch_sl[0] = data_obj.homeid;
-	data_obj.sch_el[0] = data_obj.officeid;
-	data_obj.sch_t[0] = data_obj.time1[data_obj.sch_sl[0]][data_obj.sch_el[0]];
-	data_obj.sch_type[0] = 1;
-	
-	data_obj.sch_sl[1] = data_obj.officeid;
-	data_obj.sch_el[1] = data_obj.barid;
-	data_obj.sch_t[1] = data_obj.time1[data_obj.sch_sl[1]][data_obj.sch_el[1]] ;
-	data_obj.sch_type[1] = 1;
-	
-	data_obj.sch_sl[2] = data_obj.barid;
-	data_obj.sch_el[2] = data_obj.homeid;
-	data_obj.sch_t[2] = findHybridTime(data_obj.time3[data_obj.sch_sl[2]][data_obj.sch_el[2]]);
-	data_obj.sch_type[2] = 3;
+	data_obj.sch_sl[0] = data_obj.homeid;		//start location
+	data_obj.sch_el[0] = data_obj.officeid;		//end location
+	data_obj.sch_t[0] = data_obj.time1[data_obj.sch_sl[0]][data_obj.sch_el[0]];		//time avaliable
+	data_obj.sch_type[0] = 1;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[1] = data_obj.officeid;		//start location
+	data_obj.sch_el[1] = data_obj.barid;		//end location
+	data_obj.sch_t[1] = data_obj.time1[data_obj.sch_sl[1]][data_obj.sch_el[1]];		//time avaliable
+	data_obj.sch_type[1] = 1;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[2] = data_obj.barid;		//start location
+	data_obj.sch_el[2] = data_obj.homeid;		//end location
+	data_obj.sch_t[2] = findHybridTime(data_obj.time3[data_obj.sch_sl[2]][data_obj.sch_el[2]]);		//time avaliable
+	data_obj.sch_type[2] = 3;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
 	
 	//Tuesday
-	data_obj.sch_sl[3] = data_obj.homeid;
-	data_obj.sch_el[3] = data_obj.officeid;
-	data_obj.sch_t[3] = data_obj.time2[data_obj.sch_sl[3]][data_obj.sch_el[3]];
-	data_obj.sch_type[3] = 1;
-	
-	data_obj.sch_sl[4] = data_obj.officeid;
-	data_obj.sch_el[4] = data_obj.lunchaid;
-	data_obj.sch_t[4] = data_obj.time1[data_obj.sch_sl[4]][data_obj.sch_el[4]] ;
-	data_obj.sch_type[4] = 1;
-	
-	data_obj.sch_sl[5] = data_obj.lunchaid;
-	data_obj.sch_el[5] = data_obj.officeid;
-	data_obj.sch_t[5] = data_obj.time1[data_obj.sch_sl[5]][data_obj.sch_el[5]];
-	data_obj.sch_type[5] = 1;
-
-	data_obj.sch_sl[6] = data_obj.officeid;
-	data_obj.sch_el[6] = data_obj.barid;
-	data_obj.sch_t[6] = data_obj.time2[data_obj.sch_sl[6]][data_obj.sch_el[6]];
-	data_obj.sch_type[6] = 1;
-	
-	data_obj.sch_sl[7] = data_obj.barid;
-	data_obj.sch_el[7] = data_obj.homeid;
-	data_obj.sch_t[7] = findHybridTime(data_obj.time3[data_obj.sch_sl[7]][data_obj.sch_el[7]]);
-	data_obj.sch_type[7] = 3;
+	data_obj.sch_sl[3] = data_obj.homeid;		//start location
+	data_obj.sch_el[3] = data_obj.officeid;		//end location
+	data_obj.sch_t[3] = data_obj.time2[data_obj.sch_sl[3]][data_obj.sch_el[3]];		//time avaliable
+	data_obj.sch_type[3] = 1;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[4] = data_obj.officeid;		//start location
+	data_obj.sch_el[4] = data_obj.lunchaid;		//end location
+	data_obj.sch_t[4] = data_obj.time1[data_obj.sch_sl[4]][data_obj.sch_el[4]];		//time avaliable
+	data_obj.sch_type[4] = 1;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[5] = data_obj.lunchaid;		//start location
+	data_obj.sch_el[5] = data_obj.officeid;		//end location
+	data_obj.sch_t[5] = data_obj.time1[data_obj.sch_sl[5]][data_obj.sch_el[5]];		//time avaliable
+	data_obj.sch_type[5] = 1;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+
+	data_obj.sch_sl[6] = data_obj.officeid;		//start location
+	data_obj.sch_el[6] = data_obj.barid;		//end location
+	data_obj.sch_t[6] = data_obj.time2[data_obj.sch_sl[6]][data_obj.sch_el[6]];		//time avaliable
+	data_obj.sch_type[6] = 1;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[7] = data_obj.barid;		//start location
+	data_obj.sch_el[7] = data_obj.homeid;		//end location
+	data_obj.sch_t[7] = findHybridTime(data_obj.time3[data_obj.sch_sl[7]][data_obj.sch_el[7]]);		//time avaliable
+	data_obj.sch_type[7] = 3;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
 	
 	//Wednesday
-	data_obj.sch_sl[8] = data_obj.homeid;
-	data_obj.sch_el[8] = data_obj.officeid;
-	data_obj.sch_t[8] = data_obj.time3[data_obj.sch_sl[8]][data_obj.sch_el[8]];
-	data_obj.sch_type[8] = 1;
-	
-	data_obj.sch_sl[9] = data_obj.officeid;
-	data_obj.sch_el[9] = data_obj.lunchaid;
-	data_obj.sch_t[9] = data_obj.time1[data_obj.sch_sl[9]][data_obj.sch_el[9]] ;
-	data_obj.sch_type[9] = 1;
-	
-	data_obj.sch_sl[10] = data_obj.lunchaid;
-	data_obj.sch_el[10] = data_obj.officeid;
-	data_obj.sch_t[10] = data_obj.time1[data_obj.sch_sl[10]][data_obj.sch_el[10]];
-	data_obj.sch_type[10] = 1;
-
-	data_obj.sch_sl[11] = data_obj.officeid;
-	data_obj.sch_el[11] = data_obj.barid;
-	data_obj.sch_t[11] = data_obj.time3[data_obj.sch_sl[11]][data_obj.sch_el[11]];
-	data_obj.sch_type[11] = 1;
-	
-	data_obj.sch_sl[12] = data_obj.barid;
-	data_obj.sch_el[12] = data_obj.homeid;
-	data_obj.sch_t[12] = findHybridTime(data_obj.time3[data_obj.sch_sl[12]][data_obj.sch_el[12]]);
-	data_obj.sch_type[12] = 3;
+	data_obj.sch_sl[8] = data_obj.homeid;		//start location
+	data_obj.sch_el[8] = data_obj.officeid;		//end location
+	data_obj.sch_t[8] = data_obj.time3[data_obj.sch_sl[8]][data_obj.sch_el[8]];		//time avaliable
+	data_obj.sch_type[8] = 1;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[9] = data_obj.officeid;		//start location
+	data_obj.sch_el[9] = data_obj.lunchaid;		//end location
+	data_obj.sch_t[9] = data_obj.time1[data_obj.sch_sl[9]][data_obj.sch_el[9]];		//time avaliable
+	data_obj.sch_type[9] = 1;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[10] = data_obj.lunchaid;		//start location
+	data_obj.sch_el[10] = data_obj.officeid;		//end location
+	data_obj.sch_t[10] = data_obj.time1[data_obj.sch_sl[10]][data_obj.sch_el[10]];		//time avaliable
+	data_obj.sch_type[10] = 1;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+
+	data_obj.sch_sl[11] = data_obj.officeid;		//start location
+	data_obj.sch_el[11] = data_obj.barid;		//end location
+	data_obj.sch_t[11] = data_obj.time3[data_obj.sch_sl[11]][data_obj.sch_el[11]];		//time avaliable
+	data_obj.sch_type[11] = 1;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[12] = data_obj.barid;		//start location
+	data_obj.sch_el[12] = data_obj.homeid;		//end location
+	data_obj.sch_t[12] = findHybridTime(data_obj.time3[data_obj.sch_sl[12]][data_obj.sch_el[12]]);		//time avaliable
+	data_obj.sch_type[12] = 3;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
 	
 	//Thursday
-	data_obj.sch_sl[13] = data_obj.homeid;
-	data_obj.sch_el[13] = data_obj.officeid;
-	data_obj.sch_t[13] = data_obj.time3[data_obj.sch_sl[13]][data_obj.sch_el[13]];
-	data_obj.sch_type[13] = 1;
-	
-	data_obj.sch_sl[14] = data_obj.officeid;
-	data_obj.sch_el[14] = data_obj.barid;
-	data_obj.sch_t[14] = data_obj.time3[data_obj.sch_sl[14]][data_obj.sch_el[14]];
-	data_obj.sch_type[14] = 1;
-	
-	data_obj.sch_sl[15] = data_obj.barid;
-	data_obj.sch_el[15] = data_obj.homeid;
-	data_obj.sch_t[15] = findHybridTime(data_obj.time3[data_obj.sch_sl[15]][data_obj.sch_el[15]]);
-	data_obj.sch_type[15] = 3;
+	data_obj.sch_sl[13] = data_obj.homeid;		//start location
+	data_obj.sch_el[13] = data_obj.officeid;		//end location
+	data_obj.sch_t[13] = data_obj.time3[data_obj.sch_sl[13]][data_obj.sch_el[13]];		//time avaliable
+	data_obj.sch_type[13] = 1;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[14] = data_obj.officeid;		//start location
+	data_obj.sch_el[14] = data_obj.barid;		//end location
+	data_obj.sch_t[14] = data_obj.time3[data_obj.sch_sl[14]][data_obj.sch_el[14]];		//time avaliable
+	data_obj.sch_type[14] = 1;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[15] = data_obj.barid		//start location
+	data_obj.sch_el[15] = data_obj.homeid;		//end location
+	data_obj.sch_t[15] = findHybridTime(data_obj.time3[data_obj.sch_sl[15]][data_obj.sch_el[15]]);		//time avaliable
+	data_obj.sch_type[15] = 3;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
 	
 	//Friday
-	data_obj.sch_sl[16] = data_obj.homeid;
-	data_obj.sch_el[16] = data_obj.officeid;
-	data_obj.sch_t[16] = data_obj.time3[data_obj.sch_sl[16]][data_obj.sch_el[16]];
-	data_obj.sch_type[16] = 1;
-	
-	data_obj.sch_sl[17] = data_obj.officeid;
-	data_obj.sch_el[17] = data_obj.lunchbid;
-	data_obj.sch_t[17] = data_obj.time1[data_obj.sch_sl[17]][data_obj.sch_el[17]] ;
-	data_obj.sch_type[17] = 1;
-	
-	data_obj.sch_sl[18] = data_obj.lunchbid;
-	data_obj.sch_el[18] = data_obj.officeid;
-	data_obj.sch_t[18] = data_obj.time1[data_obj.sch_sl[18]][data_obj.sch_el[18]];
-	data_obj.sch_type[18] = 1;
-
-	data_obj.sch_sl[19] = data_obj.officeid;
-	data_obj.sch_el[19] = data_obj.barid;
-	data_obj.sch_t[19] = data_obj.time3[data_obj.sch_sl[19]][data_obj.sch_el[19]];
-	data_obj.sch_type[19] = 1;
-	
-	data_obj.sch_sl[20] = data_obj.barid;
-	data_obj.sch_el[20] = data_obj.homeid;
-	data_obj.sch_t[20] = findHybridTime(data_obj.time3[data_obj.sch_sl[20]][data_obj.sch_el[20]]);
-	data_obj.sch_type[20] = 3;
+	data_obj.sch_sl[16] = data_obj.homeid;		//start location
+	data_obj.sch_el[16] = data_obj.officeid;		//end location
+	data_obj.sch_t[16] = data_obj.time3[data_obj.sch_sl[16]][data_obj.sch_el[16]];		//time avaliable
+	data_obj.sch_type[16] = 1;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[17] = data_obj.officeid;		//start location
+	data_obj.sch_el[17] = data_obj.lunchbid;		//end location
+	data_obj.sch_t[17] = data_obj.time1[data_obj.sch_sl[17]][data_obj.sch_el[17]];		//time avaliable
+	data_obj.sch_type[17] = 1;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[18] = data_obj.lunchbid;		//start location
+	data_obj.sch_el[18] = data_obj.officeid;		//end location
+	data_obj.sch_t[18] = data_obj.time1[data_obj.sch_sl[18]][data_obj.sch_el[18]];		//time avaliable
+	data_obj.sch_type[18] = 1;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+
+	data_obj.sch_sl[19] = data_obj.officeid;		//start location
+	data_obj.sch_el[19] = data_obj.barid;		//end location
+	data_obj.sch_t[19] = data_obj.time3[data_obj.sch_sl[19]][data_obj.sch_el[19]];		//time avaliable
+	data_obj.sch_type[19] = 1;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[20] = data_obj.barid;		//start location
+	data_obj.sch_el[20] = data_obj.homeid;		//end location
+	data_obj.sch_t[20] = findHybridTime(data_obj.time3[data_obj.sch_sl[20]][data_obj.sch_el[20]]);		//time avaliable
+	data_obj.sch_type[20] = 3;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
 	
 	//Saturday
-	data_obj.sch_sl[21] = data_obj.homeid;
-	data_obj.sch_el[21] = data_obj.mallid;
-	data_obj.sch_t[21] = findHybridTime(data_obj.time3[data_obj.sch_sl[21]][data_obj.sch_el[21]]);
-	data_obj.sch_type[21] = 3;
-	
-	data_obj.sch_sl[22] = data_obj.mallid;
-	data_obj.sch_el[22] = data_obj.homeid;
-	data_obj.sch_t[22] = findHybridTime(data_obj.time3[data_obj.sch_sl[22]][data_obj.sch_el[22]]);
-	data_obj.sch_type[22] = 3;
-	
-	data_obj.sch_sl[23] = data_obj.homeid;
-	data_obj.sch_el[23] = data_obj.barid;
-	data_obj.sch_t[23] = 90;
-	data_obj.sch_type[23] = 2;
-	
-	data_obj.sch_sl[24] = data_obj.barid;
-	data_obj.sch_el[24] = data_obj.homeid;
-	data_obj.sch_t[24] = findHybridTime(data_obj.time3[data_obj.sch_sl[24]][data_obj.sch_el[24]]);
-	data_obj.sch_type[24] = 3;
+	data_obj.sch_sl[21] = data_obj.homeid;		//start location
+	data_obj.sch_el[21] = data_obj.mallid;		//end location
+	data_obj.sch_t[21] = findHybridTime(data_obj.time3[data_obj.sch_sl[21]][data_obj.sch_el[21]]);		//time avaliable
+	data_obj.sch_type[21] = 3;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[22] = data_obj.mallid;		//start location
+	data_obj.sch_el[22] = data_obj.homeid;		//end location
+	data_obj.sch_t[22] = findHybridTime(data_obj.time3[data_obj.sch_sl[22]][data_obj.sch_el[22]]);		//time avaliable
+	data_obj.sch_type[22] = 3;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[23] = data_obj.homeid;		//start location
+	data_obj.sch_el[23] = data_obj.barid;		//end location
+	data_obj.sch_t[23] = 90;		//time avaliable
+	data_obj.sch_type[23] = 2;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[24] = data_obj.barid;		//start location
+	data_obj.sch_el[24] = data_obj.homeid;		//end location
+	data_obj.sch_t[24] = findHybridTime(data_obj.time3[data_obj.sch_sl[24]][data_obj.sch_el[24]]);		//time avaliable
+	data_obj.sch_type[24] = 3;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
 	
 	//Sunday
-	data_obj.sch_sl[25] = data_obj.homeid;
-	data_obj.sch_el[25] = data_obj.mallid;
-	data_obj.sch_t[25] = 60;
-	data_obj.sch_type[25] = 2;
-	
-	data_obj.sch_sl[26] = data_obj.mallid;
-	data_obj.sch_el[26] = data_obj.barid;
-	data_obj.sch_t[26] = 150;
-	data_obj.sch_type[26] = 2;
-	
-	data_obj.sch_sl[27] = data_obj.barid;
-	data_obj.sch_el[27] = data_obj.homeid;
-	data_obj.sch_t[27] = findHybridTime(data_obj.time3[data_obj.sch_sl[27]][data_obj.sch_el[27]]);
-	data_obj.sch_type[27] = 3;
-	
-	data_obj.sch_len = 28;
-	data_obj.num_ajax= 12;
-}
-
+	data_obj.sch_sl[25] = data_obj.homeid;		//start location
+	data_obj.sch_el[25] = data_obj.mallid;		//end location
+	data_obj.sch_t[25] = 60;		//time avaliable
+	data_obj.sch_type[25] = 2;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[26] = data_obj.mallid;		//start location
+	data_obj.sch_el[26] = data_obj.barid;		//end location
+	data_obj.sch_t[26] = 150;		//time avaliable
+	data_obj.sch_type[26] = 2;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_sl[27] = data_obj.barid;		//start location
+	data_obj.sch_el[27] = data_obj.homeid;		//end location
+	data_obj.sch_t[27] = findHybridTime(data_obj.time3[data_obj.sch_sl[27]][data_obj.sch_el[27]]);		//time avaliable
+	data_obj.sch_type[27] = 3;	//motion type: 1->Beeline, 2->Random, 3->Hybrid
+	
+	data_obj.sch_len = 28;		//length of the schedule
+	data_obj.num_ajax= 12;		//number of ajax calls to be made
+}
+
+/*
+The following function simulates Routine Activity, by simulating agent mvoements as per the schedule
+*/
 function simulateRoutineActivity(){
 	$("#loading").dialog('open').html("<p>Simulating First Week where no crime is committed</p>");
-	//week 1
-	data_obj.num_ajax_counter=0;		
+	//Simulating Week 1, when the agent does not commit crime
+	data_obj.num_ajax_counter=0;	
+	//Iterating through the schedule
 	for(var i=0; i<data_obj.sch_len; i++){
 		var start = data_obj.sch_sl[i];
 		var end = data_obj.sch_el[i];
 		var time = data_obj.sch_t[i];
-		var type = data_obj.sch_type[i];
-		if(i == data_obj.sch_len-1){
-			if(type == 1)simulateBeeline(start, end, time,1,0);
-			else if(type == 2)simulateRandom(start, end, time,1,0);
-			else if(type == 3)simulateHybrid(start, end, time,1,0);
-		}else{
-			if(type == 1)simulateBeeline(start, end, time,0,0 );
-			else if(type == 2)simulateRandom(start, end, time, 0,0);
-			else if(type == 3)simulateHybrid(start, end, time, 0 , 0);
-		}
+		var type = data_obj.sch_type[i];	
+		//Calling the function for the approproate type of motion as per the schedule
+		if(type == 1)simulateBeeline(start, end, time,0);
+		else if(type == 2)simulateRandom(start, end, time,0);
+		else if(type == 3)simulateHybrid(start, end, time,0);	
 	}	
 }
 
+/*
+The following function simulates Routine Activity, by simulating agent mvoements as per the schedule, for the second week onwards, wherein the agent commits crime
+*/
 function commitCrime(){
-	//week2			
+	//Iterating through the schedule	
 	for(var i=0; i<data_obj.sch_len; i++){
 		var start = data_obj.sch_sl[i];
 		var end = data_obj.sch_el[i];
 		var time = data_obj.sch_t[i];
-		var type = data_obj.sch_type[i];
-		if(i == data_obj.sch_len-1){
-			if(type == 1)simulateBeeline(start, end, time,1, 1);
-			else if(type == 2)simulateRandom(start, end, time,1, 1);
-			else if(type == 3)simulateHybrid(start, end, time,1, 1);
-		}else{
-			if(type == 1)simulateBeeline(start, end, time,0, 1);
-			else if(type == 2)simulateRandom(start, end, time, 0 , 1);
-			else if(type == 3)simulateHybrid(start, end, time, 0, 1);
-		}
+		var type = data_obj.sch_type[i];	
+		//Calling the function for the approproate type of motion as per the schedule
+		if(type == 1)simulateBeeline(start, end, time, 1);
+		else if(type == 2)simulateRandom(start, end, time, 1);
+		else if(type == 3)simulateHybrid(start, end, time, 1);		
 	}
 }
 
+/*
+The follwoing function updates the labels of the crime spot to display the number of times crime has been committed at that spot and also the updated risk
+*/
 function updateSpotLabels(){
-	for(var i=0; i<crime_spot_markers.length; i++){
+	//remove all crime-spot markers
+	for(var i=0; i<crime_spot_markers.length; i++){		
 		map.removeLayer(crime_spot_markers[i]);
 	}
+	//Add new markers
 	for(var i=0; i<data_obj.crime_spot.length; i++){
 		var risk = data_obj.crime_risk[i];
 		var reward = data_obj.crime_reward[i];
 		var freq = data_obj.crime_freq[i];
 		var pp = data_obj.pp[i];
-		var gd = data_obj.gd[i];
-		//alert(freq);
-		var marker=L.marker(data_obj.crime_spot[i], { icon: new L.Icon.Label.Default({ labelText: "CS-" + (i+1) + " ["+Math.floor(reward)+", "+Math.floor(risk)+", "+Math.floor(pp*100)/100+", "+Math.floor(gd*100)/100+", "+freq+"]"}) }).addTo(map);
-	}
-	
+		var gd = data_obj.gd[i];		
+		var popup = "["+Math.floor(reward)+", "+Math.floor(risk)+", "+Math.floor(pp*100)/100+", "+Math.floor(gd*100)/100+"]";
+		var marker=L.marker(data_obj.crime_spot[i], { icon: new L.Icon.Label.Default({ labelText: "CS-" + (i+1) + " ["+freq+"]"}) }).addTo(map).bindPopup(popup);
+		//store new markers
+		crime_spot_markers[i]=marker;
+	}	
 }
-
+/*
+The following function counts the number of ajax call that have been completed for Simulating Routine Activity
+*/
 function ajaxComplete(){	
 	data_obj.num_ajax_counter++;
-	console.log(data_obj.num_ajax_counter);
+	//If all ajax calls for simualting a particular week has compelted
 	if(data_obj.num_ajax_counter == data_obj.num_ajax){
 		data_obj.num_ajax_counter=0;
-		updateSpotLabels();		
-		$("#loading").dialog('close');
-		if(first_sim == 0){			
+		updateSpotLabels();		//update labels
+		$("#loading").dialog('close');		//close dialog		
+		if(first_sim == 0){		//If simulation for the first week just completed		
 			$("#loading").dialog('open').html("<p>Simulating Second Week where the agent commits crime</p>");
-			commitCrime();
-			first_sim =1;
+			commitCrime();		//start simualation for the second week committing
+			first_sim =1;		//indicate smulation of first week is over
 		}		
 	}
 }
 
+/*
+THE FOLLOWING FUNCTIONS ARE USED FOR VIEWING RESULTS OD DISTANCE DECAY WHEN SIMULATED ON A MAP WITH ADDITIONAL CONSTRAINTS LIKE DIFFERENT PROFIT, RISK, PRESENCE OF POLICE, PRESENCE OF GUARDIAN OF SPOT AT THE SPOT.
+*/
+
+
+/*
+The following functon works as the memory function, where it remembers the the spots it has visited and the number of times the spot has been visited. It also decides whether or not to commit crime. The function takes as input the set of points along the route and a variable indicating whether or not the agent should attempt to commit crime
+*/
+
+function markVisitedDD(points, rob){
+	var visited = new Array(data_obj.num_crime_spot);		//array to indicate whether a spot has been visited in this route
+	//initialzing all crime spots as not visited
+	for(var i=0; i<data_obj.num_crime_spot; i++){
+		visited[i]=0;
+	}
+	var crime = 0;	//whether crime has been committed at a spot
+	var last_i = 0;		//the index of the last point on the route before committing crime
+	var ptsnew = [];	//stores the points traversed
+	ptsnew.push(points[0]);		//adding first point
+	//iterating over the points along the route
+	for(var i=1; i<points.length; i++){	
+		ptsnew.push(points[i]);
+		var flag = 0;
+		//iterating over crime spots
+		for(var j=0; j<data_obj.num_crime_spot; j++){	
+			if(visited[j] == 1)continue;		//if the spot is already visited, skip it
+			if(liesWithin(data_obj.crime_spot[j], points[i-1], points[i]) == true){		//if crime spot lies in the vicinity of the agent
+				visited[j]=1;		//mark it visited
+				data_obj.crime_risk[j] +=  data_obj.maxriskpresent*0.02;		//update risk 
+				if(rob == 1){		//if the agent shoud make an attemmpt to commit crime
+					var risk = Math.random();	//random value betwnn 0 and 1
+					var profit = Math.random();	//random value betwnn 0 and 1
+					var ppp = Math.random();	//random value betwnn 0 and 1, indicating whether patrolling plolice is present in vicinity
+					var gw = Math.random();	//random value betwnn 0 and 1, indicating whether guardian of spot is away
+					if(ppp > data_obj.pp[j] ){		//if patrolling police is not present in vicinity
+						var rsk = data_obj.crime_risk[j];
+						if(gw < data_obj.gd[j]){		//if guardian of spot is away
+							rsk = rsk/2;		//reduce risk to half
+						}
+						//decide whether to take risk based on nomrmalized risk value
+						if(risk > (data_obj.risk_avoidance*rsk)/data_obj.maxriskpresent){
+							//deciding whether to commit crime based on nomarlized profit value
+							if(profit < (data_obj.profit_seeking*data_obj.crime_reward[j])/data_obj.maxprofitpossible){									
+														 
+								if(stopdd == 1){	//If the smulatin is to be stopped		
+									$("#info").dialog('close');
+									return;								
+								}
+								else{
+									//Attempt to Break-In
+									dist += distnow*i/points.length;
+									equity = equity - dist;					
+									flag = 1;
+									last_i = i;
+									var caught = Math.random();
+									if(caught < (data_obj.risk_avoidance*rsk)/data_obj.maxriskpresent){		//If caught
+										$("#info").dialog('open').html("<p>Attempt to break-in at Crime Spot "+(j+1)+": Caught!!<p>");
+										equity = 0.75*equity;		//lose 25% of equity										
+									}
+									else{
+										//If not caught
+										$("#info").dialog('open').html("<p>Attempt to break-in at Crime Spot "+(j+1)+": Success!!<p>");
+										data_obj.crime_freq[j]++;
+										equity += data_obj.crime_reward[j];		//add profit value to agent's equity								
+									}								
+								}	
+								break;							
+							}
+						}	
+					}
+				}
+											
+			}
+		}
+		if(stopdd == 1){
+			break;
+		}
+		if(flag == 1){
+			crime = 1;		//if crime has been commited break from loop to go home
+			break;
+		}		
+	}
+	//mark route on map
+	route= new L.Polyline(ptsnew, {
+		weight: 2,
+		opacity: 1,
+		color: 'blue',
+		smoothFactor: 1
+	}).addTo(map);
+	route.bringToFront();
+	//add this route to the set of routes
+	data_obj.routes.push(ptsnew);
+	if(stopdd == 1){		//If the simuation is to be stopped
+		updateSpotLabels();
+		$("#info").dialog('open').html("<p>Stopping Simulation<p>");
+		$("#info").dialog('close');		
+		return;
+	}
+	else if(crime == 1){		//If crime has been committed
+		//going back to home
+		var url = 'http://routes.cloudmade.com/81aa79a9504e4430a8a32f491ef96f07/api/0.3/'+points[last_i].lat+','+points[last_i].lng+','+data_obj.locations[data_obj.homeid].lat+','+data_obj.locations[data_obj.homeid].lng+ '/foot.js';	
+		gpcount = 0;
+		var rand_path = getPath("ajax.php", url);	
+		if(rand_path == 1){
+			stopdd= 1;
+		}
+		var pt, pts = [];
+		//adding points along the route to go back home
+		for (var i=0; i<rand_path.route_geometry.length; i++){					
+			pt = new L.LatLng(rand_path.route_geometry[i][0] , rand_path.route_geometry[i][1]);						
+			pts.push(pt);
+		}
+		data_obj.routes.push(pts);		
+		dist = dist + (rand_path.route_summary['total_distance']/1000);
+		equity = equity - dist;		//updating equity
+		//marking route on map
+		route= new L.Polyline(pts, {
+			weight: 2,
+			opacity: 1,
+			color: 'blue',
+			smoothFactor: 1
+		}).addTo(map);
+		route.bringToFront();	
+		if(stopdd == 1){		//if simualtion is to be stopped
+			updateSpotLabels();
+			$("#info").dialog('close');			
+			return;			
+		}
+		else if(equity >= 5){		//If the agent has sufficient equity
+			var start_lat = data_obj.locations[data_obj.homeid].lat;
+			var start_lon = data_obj.locations[data_obj.homeid].lng;
+			var end_lat = data_obj.locations[data_obj.homeid].lat;
+			var end_lon = data_obj.locations[data_obj.homeid].lng;				
+			$("#info").dialog('open').append("Restarting Simulation with new equity...<br>");	
+			gpcount2 = 0;   //set numner of retires to 0
+			//restart simualtion
+			simulateRandomDD(start_lat, start_lon, end_lat, end_lon);		
+		}
+		else{		//end simulation
+			updateSpotLabels();
+			$("#info").dialog('open').html("Simulation Over.");	
+			$("#info").dialog('close');		
+			return;			
+		}
+	}
+	else{			//If no crime is committed
+		dist += distnow;
+		equity = equity - distnow;				
+		if(equity >= 5){		//If agent has sufficient equity
+			var start_lat = ptsnew[ptsnew.length-1].lat;
+			var start_lon = ptsnew[ptsnew.length-1].lng;			
+			var end_lat = data_obj.locations[data_obj.homeid].lat;
+			var end_lon = data_obj.locations[data_obj.homeid].lng;
+			$("#info").dialog('open').html("Continuing Simulation...<br>");				
+			gpcount2 = 0;
+			//find path forward
+			simulateRandomDD(start_lat, start_lon, end_lat, end_lon);		
+		}
+		else{
+			//stop simulation
+			var url = 'http://routes.cloudmade.com/81aa79a9504e4430a8a32f491ef96f07/api/0.3/'+points[points.length-1].lat+','+points[points.length-1].lng+','+data_obj.locations[data_obj.homeid].lat+','+data_obj.locations[data_obj.homeid].lng+ '/foot.js';
+			gpcount = 0;
+			var rand_path = getPath("ajax.php", url);						
+			var pt, pts = [];
+			for (var i=0; i<rand_path.route_geometry.length; i++){					
+				pt = new L.LatLng(rand_path.route_geometry[i][0] , rand_path.route_geometry[i][1]);						
+				pts.push(pt);
+			}
+			//mark route
+			route= new L.Polyline(pts, {
+				weight: 2,
+				opacity: 1,
+				color: 'blue',
+				smoothFactor: 1
+			}).addTo(map);
+			//adding this route to the set of routes
+			data_obj.routes.push(pts);			
+			updateSpotLabels();		//updating the labels
+			$("#info").dialog('open').html("Simulation Over<br>");				
+			$("#info").dialog('close');
+			return;
+		}
+	}
+}
+
+/*
+The following function simulates the random motion for simulating Distacne Decay
+*/
+function simulateRandomDD(start_lat, start_lon, end_lat, end_lon){	
+	if(stopdd == 1) return;
+	var flag = 0;
+	var check = 0;
+	var randomsim = $.ajax({
+		type: "POST",
+		url: "routing2.php",		   
+		data : {
+			start_lat : start_lat ,
+			start_lon : start_lon ,
+			end_lat : end_lat ,
+			end_lon : end_lon ,
+			time : 200				
+		},
+		success: function(data){
+			check = 1;			
+			if(ddcount >= 1){	//If simuation is for Distance Decay
+				ddCounter();	//call function to track number of ajax calls that have returned successfully
+			}
+			else{	//If simuation is for Routine Activity
+				ajaxComplete();		//call function to track number of ajax calls that have returned successfully
+			}					
+			var rand_path = data;
+			var status = rand_path.status;
+			if(data == "" || status != '0'){		//if ajax call did not return the required response
+				gpcount2++;		//increment the number of retries
+				if(gpcount2<=3)setTimeout(simulateRandomDD(start_lat, start_lon, end_lat, end_lon),500);		//retry again if number of previous retires is not more than 3	
+				else{
+					$("#info").dialog('close');			//close the diaolog	
+					return;
+				}	
+			}
+			else{	//if ajax call returns an expected response
+				distnow = (rand_path.route_summary['total_distance'])/1000;		//distance travelled in this path			
+				var pt, pts = [];
+				//storing points along this route
+				for (var i=0; i<rand_path.route_geometry.length; i++){					
+					pt = new L.LatLng(rand_path.route_geometry[i][0] , rand_path.route_geometry[i][1]);						
+					pts.push(pt);
+				}								
+				markVisitedDD(pts, 1);		//calling function for memory and deciding whether is committed
+			}			
+		},
+		error: function(){	//error in ajax request
+			//retry for maximum 3 times
+			gpcount2++;
+			if(gpcount2<=3)setTimeout(simulateRandomDD(start_lat, start_lon, end_lat, end_lon),500);
+			else{
+				$("#info").dialog('close');			
+				return;
+			}		
+		}
+	});	
+}
+
+/*
+The following function simulates distacne decay on map with additional contraints like different profit value, risk value with each crime spot, prsence of patrolling police, absence of victime agent (guardian) from teh spot
+*/
+function simulateDistanceDecay(){
+	var start_lat = data_obj.locations[data_obj.homeid].lat;		//Latitude of Start Point
+	var start_lon = data_obj.locations[data_obj.homeid].lng;		//Longitude of Start Point
+	var end_lat = start_lat;		//Latitude of End Point
+	var end_lon = start_lon;		//Longitude of End Point			
+	gpcount2 = 0;
+	simulateRandomDD(start_lat, start_lon, end_lat, end_lon);	//simalate Random movement	
+}
+
+//The following function counts the number of ajax calls that have completed
+function ddCounter(){	
+	ddcount++;		
+}
+
+/*
+The foolwing function is used to read the GeoJSON file and display it on map with required alebls stores
+*/
+function onEachFeature(feature, layer) {
+    if (feature.geometry.type == "Point"){		//If the geometry is a point
+		if(feature.properties.risk) {		//If it is a crime spot				
+			pt = new L.LatLng(feature.geometry.coordinates[1] , feature.geometry.coordinates[0]);	//latitude and Longitude
+			data_obj.crime_spot[feature.properties.id] = pt;	//ID of crime spot
+			data_obj.crime_reward[feature.properties.id] = feature.properties.reward;	//Reward
+			data_obj.crime_risk[feature.properties.id] = feature.properties.risk;		//Risk
+			data_obj.crime_freq[feature.properties.id] = feature.properties.freq;		//Number of successful crime has been committed
+			data_obj.pp[feature.properties.id] = feature.properties.pp;		//Probability of presence of patrolling police in vicinity of crime spot
+			data_obj.gd[feature.properties.id] = feature.properties.gd;		//Probability that guardian of crime spot is away
+			var popup = '['+Math.floor(feature.properties.reward*100)/100+', '+Math.floor(feature.properties.risk*100)/100+', '+Math.floor(feature.properties.pp*100)/100+', '+Math.floor(feature.properties.gd*100)/100+']';		//label to dislay on popup
+			var marker=L.marker(pt, { icon: new L.Icon.Label.Default({ labelText:  feature.properties.label }) }).addTo(map).bindPopup(popup);	//adding marker with label and popup to map
+			crime_spot_markers.push(marker);		//storing marker
+		}
+		else{		//If it is location - home or mall or bar or lunch-A or lunch-B or office			
+			pt = new L.LatLng(feature.geometry.coordinates[1] , feature.geometry.coordinates[0]);			//Latitude and Longitude		
+			var marker=L.marker(pt, { icon: new L.Icon.Label.Default({ labelText:  feature.properties.label }) }).addTo(map);		//adding marker with label to the map
+		}
+	}
+	else if(feature.geometry.type == "LineString"){			//path
+		var pt, pts = [];
+		for (var i=0; i<feature.geometry.coordinates.length; i++){					
+			pt = new L.LatLng(feature.geometry.coordinates[i][0] , feature.geometry.coordinates[i][1]);						
+			pts.push(pt);
+			data_obj.routes.push(pts);			//storing path in object		
+		}
+		var myStyle = {		//styles associates with polyline
+			"color": "blue",
+			"weight": 2,
+			"opacity": 1	
+		};
+		//displaying route on map
+		L.geoJson(feature, {
+			style: myStyle
+		}).addTo(map);
+				
+	}
+}
+
+/*
+The following function loads data from GeoJSON and displays it on the map after initalizing the object
+*/
+function load(geo){
+	map.setView([data_obj.city_lat, data_obj.city_lon], data_obj.zoom);		//setting map
+	//initialzing object
+	data_obj.routes = new Array();
+	data_obj.crime_spot = new Array();
+	crime_spot_markers = new Array();
+	data_obj.crime_reward = new Array();
+	data_obj.crime_risk = new Array();
+	data_obj.crime_freq = new Array();
+	data_obj.pp = new Array();  //prob that patrolling police is present in vicinity
+	data_obj.gd = new Array();  //prob that guardian is away
+	//reading data form the GeoJSON file
+	L.geoJson(geo, {
+		onEachFeature: onEachFeature
+	})
+}
+
+/*
+The following function generates a JSON string from the object. This is used for storing non-spatial data on the server like schedule.
+*/
+function generateJson(){
+	var obj = new Object();	
+	obj = data_obj;	
+	return JSON.stringify(obj);
+}
+
+/*
+The following function is used to find a path between to points. The function makes an ajax call to a server side script - "ajax.php". The input paraemeters are target which is the name of the server side script and url, which contains information about the path to find
+*/
+function getPath(target, url){	
+	var dat;
+	//making ajax call
+	var randomsim = $.ajax({
+		type: "POST",
+		url: target,		   
+		data : {
+			url : url	
+		},	
+		async : false,
+		success: function(data){			
+			dat = data;			
+			var status = data.status;
+			if(status != '0'){	//if ajax call returns unexpected value
+				//retry for maximum 3 times after a pause of 500 ms
+				gpcount++;
+				if(gpcount <= 3)setTimeout(getPath(target, url),500);				
+			}			
+		}									
+	});	
+	if(gpcount > 3){	//If more the 3 reties have failed
+		dat = 1;
+		stopdd=1;
+	}
+	return dat;		//return the path	
+}
+
+
+
 
 
 

Added: sis/sandbox/gsoc2013/crimgeoprofile/js/geojson_generator.js
URL: http://svn.apache.org/viewvc/sis/sandbox/gsoc2013/crimgeoprofile/js/geojson_generator.js?rev=1525754&view=auto
==============================================================================
--- sis/sandbox/gsoc2013/crimgeoprofile/js/geojson_generator.js (added)
+++ sis/sandbox/gsoc2013/crimgeoprofile/js/geojson_generator.js Tue Sep 24 00:12:22 2013
@@ -0,0 +1,137 @@
+/*
+The following converts the data in the object to GeoJSON format. It does so by creating an object that has properties and attributes corresponding to GeoJSON format. This object when parsed gives a string in GeoJSON format
+*/
+
+function generateGeoJson(data_obj){
+	//Object saving map related data in GeoJSON format
+	map_obj = new Object();	   	
+	//initialising map_obj
+	map_obj.type = "FeatureCollection";
+	map_obj.features = new Array();
+	
+	//adding home
+	if(data_obj.homeid >= 0){
+		var obj = new Object();
+		obj.type = "Feature";
+		obj.geometry = new Object();
+		obj.properties = new Object();
+		obj.properties.label = "Home";		//Label
+		obj.properties.id = data_obj.homeid;	//Location ID	
+		obj.geometry.type = "Point";	//Geometry Type
+		obj.geometry.coordinates = new Array();	
+		obj.geometry.coordinates.push(data_obj.locations[obj.properties.id].lng);		//Longitude
+		obj.geometry.coordinates.push(data_obj.locations[obj.properties.id].lat);		//Longitude
+	}
+	map_obj.features.push(obj);
+	
+	//adding bar
+	if(data_obj.barid >= 0){
+		var obj = new Object();
+		obj.type = "Feature";
+		obj.geometry = new Object();
+		obj.properties = new Object();
+		obj.properties.label = "Bar";		//Label
+		obj.properties.id = data_obj.barid;			//Location ID	
+		obj.geometry.type = "Point";
+		obj.geometry.coordinates = new Array();		
+		obj.geometry.coordinates.push(data_obj.locations[obj.properties.id].lng);		//Longitude
+		obj.geometry.coordinates.push(data_obj.locations[obj.properties.id].lat);		//Longitude	
+	}
+	map_obj.features.push(obj);
+	
+	//adding Office
+	if(data_obj.officeid  >= 0){
+		var obj = new Object();
+		obj.type = "Feature";
+		obj.geometry = new Object();
+		obj.properties = new Object();
+		obj.properties.label = "Office";		//Label
+		obj.properties.id = data_obj.officeid;	//Location ID			
+		obj.geometry.type = "Point";
+		obj.geometry.coordinates = new Array();		
+		obj.geometry.coordinates.push(data_obj.locations[obj.properties.id].lng);		//Longitude
+		obj.geometry.coordinates.push(data_obj.locations[obj.properties.id].lat);		//Longitude	
+	}
+	map_obj.features.push(obj);
+	
+	//adding Lunch-A 
+	if(data_obj.lunchaid  >= 0){
+		var obj = new Object();
+		obj.type = "Feature";
+		obj.geometry = new Object();
+		obj.properties = new Object();
+		obj.properties.label = "Lunch-A";		//Label
+		obj.properties.id = data_obj.lunchaid;	//Location ID			
+		obj.geometry.type = "Point";	//Geometry Type
+		obj.geometry.coordinates = new Array();	
+		obj.geometry.coordinates.push(data_obj.locations[obj.properties.id].lng);		//Longitude
+		obj.geometry.coordinates.push(data_obj.locations[obj.properties.id].lat);		//Longitude	
+	}
+	map_obj.features.push(obj);
+	
+	//adding Lunch-B
+	if(data_obj.lunchbid >= 0){
+		var obj = new Object();
+		obj.type = "Feature";
+		obj.geometry = new Object();
+		obj.properties = new Object();
+		obj.properties.label = "Lunch-B";		//Label
+		obj.properties.id = data_obj.lunchbid;		//Location ID		
+		obj.geometry.type = "Point";		//Geometry Type
+		obj.geometry.coordinates = new Array();	
+		obj.geometry.coordinates.push(data_obj.locations[obj.properties.id].lng);		//Longitude
+		obj.geometry.coordinates.push(data_obj.locations[obj.properties.id].lat);		//Longitude	
+	}
+	map_obj.features.push(obj);
+	
+	//adding Mall
+	if(data_obj.mallid >= 0){
+		var obj = new Object();
+		obj.type = "Feature";
+		obj.geometry = new Object();
+		obj.properties = new Object();
+		obj.properties.label = "Mall";		//Label
+		obj.properties.id = data_obj.mallid;	//Location ID			
+		obj.geometry.type = "Point";	//Geometry Type
+		obj.geometry.coordinates = new Array();
+		obj.geometry.coordinates.push(data_obj.locations[obj.properties.id].lng);		//Longitude
+		obj.geometry.coordinates.push(data_obj.locations[obj.properties.id].lat);		//Longitude	
+	}
+	map_obj.features.push(obj);
+	
+	//adding routes	
+	for(var i=0; i<data_obj.routes.length; i++){
+		var obj = new Object();
+		obj.type = "Feature";
+		obj.geometry = new Object();
+		obj.geometry.type = "LineString";	//Geometry Type
+		obj.geometry.coordinates = new Array();
+		for(var j=0; j<data_obj.routes[i].length; j++){
+			obj.geometry.coordinates[j] = new Array();
+			obj.geometry.coordinates[j].push(data_obj.routes[i][j].lng);		//Longitude
+			obj.geometry.coordinates[j].push(data_obj.routes[i][j].lat);		//Longitude
+		}
+		map_obj.features.push(obj);
+	}	
+	
+	//adding crime spots
+	for(var i=0; i<data_obj.num_crime_spot; i++){
+		var obj = new Object();
+		obj.type = "Feature";
+		obj.geometry = new Object();
+		obj.properties = new Object();
+		obj.properties.id = i;	//ID of crime spot
+		obj.properties.risk = data_obj.crime_risk[i];		//Risk	
+		obj.properties.reward = data_obj.crime_reward[i];		//Reward
+		obj.properties.freq = data_obj.crime_freq[i];		//Number of times crime has been committed
+		obj.properties.pp = data_obj.pp[i];		//Probability that Patrolling Police is present in vicinity of the spot
+		obj.properties.gd = data_obj.gd[i];		//Probability that victim-Agent (Guardian) is present in vicinity of the spot
+		obj.properties.label = "CS-"+(obj.properties.id+1)+'['+obj.properties.freq+']';			//Label		
+		obj.geometry.type = "Point";	//Geometry Type
+		obj.geometry.coordinates = new Array();
+		obj.geometry.coordinates.push(data_obj.crime_spot[obj.properties.id].lng);		//Longitude
+		obj.geometry.coordinates.push(data_obj.crime_spot[obj.properties.id].lat);		//Longitude	
+		map_obj.features.push(obj);	
+	}	
+	return JSON.stringify(map_obj);		//convert object to string in valid GeoJSON format	
+}
\ No newline at end of file



Mime
View raw message