Sunday, August 21, 2011

Lift/Elevator Management Systems: Part I

I have been always intrigued by how Lift/Elevators work and wanted to write a custom Algorithm in Java/SWT.

Below is a Class Diagram Generated from the source. I have split the entire source into

1. Entities : Working Objects such Lift and Floors
2. Worker Collector Interfaces : Collector Interfaces for managing Floor Requests.


Entities Class Diagram




Worker Collector Interfaces


The eclipse compatible source code is available at LiftManagement




Tuesday, June 7, 2011

Heaven or Hell



Over a dinner with friends a very interesting question was asked.The problem statement is given below.I tried reasoning the answer using Truth Table.

Problem Statement
"Two gatekeepers are standing in front of Hell and Heaven i.e one of them is in front of Hell and the other in front of Heaven. One of them tells the truth and the other lie.
If a third person is allowed to ask just one question to either of the above guys, how will he know which is hell and which is heaven?"


Solution:

In simple terms the anwser is that the third person will ask one of the gatekeeper
"what will the other gatekeeper say which is heaven or hell?"

Some prerequistes:

Let the two gatekeepers be Joe and Janet

Initial Assumption:
Joe knows
What Joe will say when asked about heaven or hell i.e they know the absolute truth.
Janet Knows:
What Janet will say when asked about heaven or hell i.e they know the absolute truth.

Joe Compliment Means Joe Tells about What Janet will say.

Reverse Janets Truth Table values : 1’ to 0 and 0 to 1

Janet’s Compliment: Means Janet Tells about What Joe will say.

Reverse Joe’s Truth Table values : 1’ to 0 and 0 to 1

Scenario 1:

Prerequisites:

Joe says truth and stays in Heaven.

Janet says lie and stays in Hell ;-)

1 is heaven and 0 is hell.

S.NO

Person

Truth Value for Joe

Truth Value for Janet

1

Joe knows

1

0

2

Janet Knows

1

0

3

Janet will say(Compliment(2))

0

1

4

Joe Will say

1

0

Hence Reversing (or complimenting again) Janet’s or Joe’s Complimented Truth ,since were are allowed to ask only one question will determine which is heaven and which is hell.

Absolute Truth of Joe

Absolute Truth of Janet

Since Janet Lies Compliment 3

Compliment(3)

1

0

Absolute Truth of Joe

Absolute Truth of Janet

Get value from column 4

1

0

Hence Joe is in heaven and can be derived at by asking question to either Janet or Joe.


Scenario 2:

Prerequisites:

Joe says truth and stays in Hell.

Janet says lie and stays in Heaven .

1 is heaven and 0 is hell.

S.NO

Person

Truth Value for Joe

Truth Value for Janet

Remark

1

Joe knows(Absolute Truth)

0

1

2

Janet Knows(Absolute Truth)

0

1

3

Janet will say(Compliment(2))

1

0

4

Joe Will say

0

1

Remains as is .. since he says the truth

Absolute Truth of Joe

Absolute Truth of Janet

Since Janet Lies Compliment 3

Compliment(3)

0

1

Absolute Truth of Joe

Absolute Truth of Janet

4

0

1

Hence this time around Janet is heaven and can be derived at by asking question to either Janet or Joe.

Scenario 3:

Prerequisites:

Joe says lie and stays in Heaven.

Janet says truth and stays in Hell.

1 is heaven and 0 is hell.

S.NO

Person

Truth Value for Joe

Truth Value for Janet

Remark

1

Joe knows(Absolute Truth)

1

0

2

Janet Knows(Absolute Truth)

1

0

3

Janet will say

1

0

4

Joe Will say(Compliment(1))

0

1

Since Joe Lies

Absolute Truth of Joe

Absolute Truth of Janet

Since Joe Lies Compliment 3

Compliment(3)

1

0

Absolute Truth of Joe

Absolute Truth of Janet

4

1

0

Hence Joe would be in heaven even though he lied.

Scenario 4:

Prerequisites:

Joe says lie and stays in Hell.

Janet says truth and stays in Heaven.

1 is heaven and 0 is hell.

S.NO

Person

Truth Value for Joe

Truth Value for Janet

Remark

1

Joe knows(Absolute Truth)

0

1

2

Janet Knows(Absolute Truth)

0

1

3

Janet will say

0

1

4

Joe Will say(Compliment(1))

1

0

Since Joe Lies

Absolute Truth of Joe

Absolute Truth of Janet

Since Joe Lies Compliment 3

Compliment(3)

1

0

Absolute Truth of Joe

Absolute Truth of Janet

4

1

0

Hence Janet would be in heaven even though he lied.

If you still think you havent got it, write a comment ;-).. After all we all want to go to heaven and you dont want to miss the question when asked at the "Pearly Gates".



Wednesday, May 4, 2011

Augmented Reality

Recently had the opportunity to evaluate some Augmented Reality Tools. Below is my take on those tools :

Layar and Junaioare Location Based Augmented Reality services, but they also provided support Marker Based Augmented reality. Most of analysis below is clearly focused on Marker Based Augmented reality.

Layar



Summary
Layar Architecture uses GPS for sending request to Layar Server and eventually to POI (Point of Interest) endpoint. It mandates the Layers to be created on their public site.




POI Endpoint
As pictorially shown below the Layar server talks to a service end point which in turn returns the information related to POI (Point of Interest). This POI is used
By the Layar Client i.e. the AGR (Augmented Reality) Browser to overlay the information over an image. Layar documentation states that we would need
a Public web server to host this service.


Pros

1.Exposes Developer API for Layar Registration.

Cons

1.The layer(s) needs to be registered to the Layar public site; since we are looking at retailers it is not possible to host retailer internal data to public sites.
2.The support for marker based augmented reality is still in its nascent stages.

Junaio Glue by Junaio



The idea is to use Junaio's Glue Technology to attach 3D objects to Patterns.We still have to define the channels like layars on Junaio's Site. The Glue Channels help us upload matching patterns along with Models and information related to object to the Junaio site.

On the Mobile Client one would download Juanio and access the newly defined Channel. Junaio browser scans the pattern.

Advantages
1.Channels can be defined private, hence in a way security can be dealt with, though the secure approach adopted by Junaio may not match private enterprise data protection.
2.Callback URL similar in the lines Layar can be configured to define patterns to be matched and the object to be overlayed on top of an image.
3.The technology for Marker based Augmented Reality is mature.
4.Allows ability to write code for defining pattern matching.

Why not a feasible solution?

1.Callback URL that one configures for different channel needs to be public , for private enterprises this could be security hazard.

Unifeye SDK Metaio



A Comprehensive SDK for Tracking Markers and overlaying images on top of patterns. Using the SDK one can rapidly create an augmented reality application for the mobile device mentioned below.
• iPhone
• Symbian S60
• Windows Mobile
• Android

Architecture Diagram



Advantages
1.SDK Layer is the High level interface which a Mobile application developer can easily use.
2.Very effective Marker Matching Pattern SDK.
3.Sample Demo Applications to get started.
4.Good Documentation.



Artoolworks


The offerings by Artoolworks is great , but they come with licensing cost.
Hence cant comment on the same. I will still recommend Artoolworks since they are
in a way pioneers in Augmented Reality.



You want for free



AndAR (Android ARToolKit)is an open source tool kit for trying Augmented Reality. You want to get some thing up quick and dirty.. This is the tool for you.

Social Media Integration

Recently I had the opportunity of Integrating Social Media Apps with Some of Our Products.Below are some Important Observations.


•All social media network APIs provide simple HTTP POST-based API’s to post messages/photos.

•The integration is highly secure because posting on social sites is done via Oauth Protocol, which relies on an access token rather than user name and password. Facebook and Foursquare support Oauth 2.0 and Twitter supports Oauth 1.0.

•The API access has the right to perform all operations which a Facebook, Twitter or Foursquare user would have as long as the user has appropriate permissions. Permissions can be given at a granular level; hence customers can restrict access to the posting component.

•The response from all of the API’s are in JSON format. The Open Source JSON parsing API was used for marshalling and unmarshalling data records.

•Each object in the social media data is associated with a unique id. This unique id changes over time. For example, the profile id for a specific user can vary per session. Search API’s for each site were used to fetch the correct profile/object id prior to posting any message(s).

•Oauth 2.0 Protocol not supported on Twitter,Extra code needs to be written to generate authorization header every time any request is sent to Twitter.Twitter Integration because of Older OAuth Protocol is cumbersome.

•APIs for posting messages are not consistent. Facebook and Foursquare use HttpClient. The post to Twitter is based on urlconnection-based posting. Oauth 1.0 Twitter posting using HttpClient needs to be explored.


Source Code
The API is written in java and uses Commons HttpClient for Posting Request to Social Media API's
Source Code

What is OAuth Dance?

How to Get Auth Token:

How to Get Auth Facebook


How to get Auth Token for Foursquare:


App Developer Doc

Twitter
Facebook
Foursquare


Recommended Library:
Twitter4J for Twitter. It is recommended to use this API for Twitter since generation of Auth Header using HttpClient is still a tedious task in twitter now since it is still on OAuth 1.0.

Facebook and Foursquare have already moved to OAUTH 2.0 making the process of generating Security Headers less difficult.

Tuesday, February 1, 2011

Constructors in Scala !!

In scala there are contructors of two types.

1. Primary
2. Auxillary

The primary constructor is the entire body of the class. Any parameters that the constructor requires are listed after the class name.

Simple Primary Constructor




class PrimaryConstructor(msg:String) {
// The message body is the primary constructor
println(msg);
}
object Invoke extends Application {
new PrimaryConstructor("Hello From PrimaryConstructor")
}


Observation
javap of the PrimaryConstructor.class gives the below mentioned result.

Corresponding Java Class Looks like the one below
public class PrimaryConstructor extends java.lang.Object implements scala.ScalaObject
{
public PrimaryConstructor(java.lang.String);
}



Simple Primary Constructor With Val


Adding a Val in the constructor parameter creates a public accessors and a private field of that reference.


class PrimaryConstructorVal(val msg:String) {
// The message body is the primary constructor
println(msg);
}
object InvokeVal extends Application {
new PrimaryConstructorVal("Hello From PrimaryConstructorVal")
}


Observation
javap of the PrimaryConstructorVal.class gives the below mentioned result.

Corresponding Java Class Looks like the one below
public class PrimaryConstructorVal extends java.lang.Object implements scala.ScalaObject{
private msg;
public java.lang.String msg();
public PrimaryConstructorVal(java.lang.String);
}

Simple Primary Constructor with Var


If a parameter has the var keyword, a public writer method is also generated with the parameter’s name as a prefix, followed by _=. For example, if label were declared as a var, the writer method would be named label_= and it would take a single argument of type String.

class PrimaryConstructorVar(var msg:String) {
// The message body is the primary constructor
println(msg);
}
object InvokeVar extends Application {
new PrimaryConstructorVar("Hello From PrimaryConstructorVar")
}

Observation
javap of the PrimaryConstructorVar.class gives the below mentioned result.

Corresponding Java Class Looks like the one below
public class PrimaryConstructorVar extends java.lang.Object implements scala.ScalaObject{
public java.lang.String msg();
public void msg_$eq(java.lang.String);
public PrimaryConstructorVar(java.lang.String);
}

Simple Primary Constructor with Private Var/val


Adding the private keyword before the val or var keyword and the accessor methods won’t be generated.

class PrimaryConstructorPrivateVar(private var msg:String) {
// The message body is the primary constructor
println(msg);
}
object InvokePrivateVar extends Application {
new PrimaryConstructorPrivateVar("Hello From PrimaryConstructorPrivateVar")
}

Observation
javap of the PrimaryConstructorPrivateVar.class gives the below mentioned result.

public class PrimaryConstructorPrivateVar extends java.lang.Object implements scala.ScalaObject{
public PrimaryConstructorPrivateVar(java.lang.String);
}


Auxiliary Constructor


Auxiliary Constructors are Scalas way of handling multiple constructors with in a call.
1.First statement of auxiliary constructor must be a call to the another constructor of the same class and it should be declared before the calling constructor.
2.In Scala, super constructor can only be called from the primary constructor.


class AuxiliaryConstructor(wish:String,givenName:String,surName:String) {
// The message body is the primary constructor
def this(wish:String,givenName: String) = this(wish:String,givenName, "")
def SayHi() = println(wish+" "+givenName + " "+surName)
}
object InvokeAuxiliaryConstructor extends Application {
val constructor1 = new AuxiliaryConstructor("Hello From Contructor with Given Name","Joe")
constructor1.SayHi()
val constructor2 =new AuxiliaryConstructor("Hello From Contructor with Given/Surname Name","Steve","Meyer")
constructor2.SayHi()
}

Observation
javap of the AuxiliaryConstructor.class gives the below mentioned result.

//public class AuxillaryConstructor extends java.lang.Object implements scala.ScalaObject{
public AuxillaryConstructor(java.lang.String, java.lang.String);
public void SayHi();
public AuxillaryConstructor(java.lang.String, java.lang.String, java.lang.String);
}

Contructors
More About Constructors
Some More about Constructors