Department of Electrical and Computer Engineering Facebook page


  • DEPARTMENT
    • Overview
    • Computing
    • Facilities
    • Organizations
    • Educational Objectives
    • Student Outcomes
    • Scholarship Awards
    • Employment
    • Advisory Committee
    • Contact
  • ACADEMICS
    • Undergraduate
      • Computer Eng.
      • Electrical Eng.
      • Ambassadors
    • Graduate
      • Information for Prospective Students
      • ECE Graduate Handbook
      • Graduate Forms
      • Ph.D. Qualifying Exam
      • Distance Education
      • Frequently Asked Questions (FAQ)
    • Courses
    • Student Survival kit
    • Distance Learning
  • PEOPLE
    • Faculty
    • Staff
  • PROSPECTIVE STUDENTS
    • Overview
    • FAQ
    • Considering ECE
    • Scholarships
    • PC Requirements
    • Office of Admissions
  • RESEARCH
    • Overview
    • Signal Processing & Communications
    • Digital Systems & Microelectronics
    • Power & High Voltage
    • Research Centers
      • Emerging Materials Research Laboratory
      • High Voltage Laboratory
      • Robotics
    • HPCC
  • ALUMNI
Sensor Networks Assignment 3 Hints - Ece
Personal tools
  • Log in
Views
  • Page
  • Discussion
  • View source
  • History

Sensor Networks Assignment 3 Hints

From Ece

Jump to: navigation, search

Hashing A String Into X,Y Coordinates

Here is a really simple way to hash any string value into a list of x and y coordinates. Note: width and height are the maximum x and y values you want returned.

  def hashStringToCoord(self, s, width, height):        
       random.seed(hash(s))         
       return [random.random()*width, random.random()*height]

It is ok to use random() here because you seed it right before you use it. Since you seed the random number generator with the hash value of the string, you will always get the same result for a given string, which is required by the geographic hash table algorithm.


Another Way to Hash Coordinates

Here is another way you could hash a key value to x,y coordinates. I just concatenated the same string again to get a different digest for the y value:

   def hashCoords(self, s, xmax, ymax):
       m = md5.new(s)
       x = m.hexdigest()
       m.update(s)
       y = m.hexdigest()
       return[int(x, 16) % xmax, int(y, 16) % ymax]

My main reason for posting this was to ask how you are implementing the perimeter search. I am hung up on how to tell when you are at the node that is closest to the hashed value. Do you have to go around the perimeter twice and keep a list of nodes traversed? Someone who has this done, let me know. Thanks. ~Terry

Terry, I implemented my perimeter search by always forwarding packets to the node which has the smallest angle returned by the function getAngle() (see below). In the payload of the message i have a list of node id's with their corresponding distances to the destination cordinate. Once i have made a complete loop around the destination (my node id appears twice in the list), I check to see if my distance to the destination is the smallest one listed for all nodes on the perimiter of the destination. If i am the closest node, then i am the host for that data, if i am not the closest node, then i am a replica (mirror) for that data. Hope that helped -Craig

Calculating Angles With Respect To A Given Destination Coordinate

I know my explanation in class on how to calculate angles was kind of confusing, so i thought i would give an example. Note: the following code assumes that the coordinate (0,0) is in the upper left. If it is in the lower left then remove the -1 in the getPositiveDegrees() function.

   def getPositiveDegrees(self, start, dest):
       theta = -1 * math.degrees(math.atan2(dest[1] - start[1], dest[0] - start[0])) + 360
       return (theta % 360)
       
       
   def getAngle(self, startCoord, destCoord, neighborCoord):
       offset = self.getPositiveDegrees(startCoord, destCoord)
       theta  = self.getPositiveDegrees(startCoord, neighborCoord)
       return ((360 - (offset - theta)) % 360)

The input parameters are lists which contain two elements, x and y. Calling getAngle() will produce an angle between 0 and 360 degrees. To find the appropriate neighbor node to forward a message too, simply find the neighbor node with the smallest angle returned by getAngle(). You could save some computation time and "power" by keeping everything in radians, but understanding this algorithm is hard enough, so i think degrees are appropriate.

Retrieved from "http://www.ece.msstate.edu/wiki/index.php/Sensor_Networks_Assignment_3_Hints"
Navigation
  • Main Page
  • Community portal
  • Current events
  • Recent changes
  • Random page
  • Help
SEARCH
TOOLBOX
LANGUAGES
 
Toolbox
  • What links here
  • Related changes
  • Upload file
  • Special pages
  • Printable version
  • Permanent link
Powered by MediaWiki
  • This page was last modified on 28 March 2007, at 04:18.
  • This page has been accessed 1,628 times.
  • Privacy policy
  • About Ece
  • Disclaimers

Mississippi State University Home| PO Box 9571, Mississippi State, MS 39762 | Main Office: 1.662.325.3912

Bagley College of Engineering | Mississippi State University| Legal| Webmaster| Intranet

Page modified: Tue, 23 Sep 2008 15:18:39 CDT