Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 30th, 2007, 9:20 PM   #1
thenewkid
Programmer
 
Join Date: Sep 2004
Location: New Jersey
Posts: 36
Rep Power: 0 thenewkid is on a distinguished road
Send a message via AIM to thenewkid
interrupting current execution

hey all, for my programming course i was to write a progam that uses a combinatorial search to find a solution, the problem is of course, that as the amount of data increases so is the time to find a solution. What i want to do is to interrupt such a time taking search and go onto the next possible candidate that might produce a correct answer. Without using threads is it possible to employ a timer of some sort so when the processing takes too long it could interrupt and tell it to move on to the next candidate? This is the Knight Tour problem, i guess many of you have dealt with it one point in your lifetime. Any advice greately appreciated.
thenewkid is offline   Reply With Quote
Old Jan 30th, 2007, 9:30 PM   #2
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
I would recommend looking into some more efficient ways in organizing your data. Maybe sorting your data would make the search A LOT more manageable.

Instead of having your data as just some random places just organize and use binary search.
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Jan 30th, 2007, 9:43 PM   #3
thenewkid
Programmer
 
Join Date: Sep 2004
Location: New Jersey
Posts: 36
Rep Power: 0 thenewkid is on a distinguished road
Send a message via AIM to thenewkid
yes i know it could be done more efficiently if more advanced data structures than simple array have been used, thats not the point here, Im looking for the way to interrupt something that takes to long to arrive at the correct answer.
thenewkid is offline   Reply With Quote
Old Jan 31st, 2007, 3:46 AM   #4
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Why not just check the time at each iteration or recursion of the loop? It seems to me as if you wouldn't need threads.
Arevos is offline   Reply With Quote
Old Jan 31st, 2007, 9:51 AM   #5
thenewkid
Programmer
 
Join Date: Sep 2004
Location: New Jersey
Posts: 36
Rep Power: 0 thenewkid is on a distinguished road
Send a message via AIM to thenewkid
you just made me think of something that could actually work, ill try something similar...ill let you all know if it worked, thanks
thenewkid is offline   Reply With Quote
Old Jan 31st, 2007, 8:36 PM   #6
thenewkid
Programmer
 
Join Date: Sep 2004
Location: New Jersey
Posts: 36
Rep Power: 0 thenewkid is on a distinguished road
Send a message via AIM to thenewkid
I found a place in my code where i could call elapsed() which made following code usable. Sometimes when i overthink a problem i do not see really simple solutions, I tend to think of too complicated stuff....are u like that? hehe, i mean look at this:

import java.util.Date;

public class myTimer {
   private final Date start;
   private Date current;
   
   public myTimer()  {
      start = new Date();
      current = null;
   }
   
   public boolean elapsed(int sec) {
      current = new Date();
      long difference = current.getTime() - start.getTime();
      if(difference >= (long)sec * 1000)
         return true;
      else return false;
   }
}

Arevos! thanks for opening my eyes lol
thenewkid is offline   Reply With Quote
Old Jan 31st, 2007, 9:24 PM   #7
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 856
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Your code creates a new Date object every time elapsed is called. You should use System.currentTimeMillis() instead.

You should also take into account the fact that performing such a check on each iteration of a loop will cost time and processing power, albeit a miniscule amount.
titaniumdecoy is online now   Reply With Quote
Old Feb 2nd, 2007, 7:45 PM   #8
thenewkid
Programmer
 
Join Date: Sep 2004
Location: New Jersey
Posts: 36
Rep Power: 0 thenewkid is on a distinguished road
Send a message via AIM to thenewkid
yes, i've relized it, thanks for pointing me to the right function
thenewkid is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
linked list problems bl00dninja C++ 6 Feb 17th, 2008 10:30 AM
singly-linked list templaste class in C++ w/ example driver bl00dninja Show Off Your Open Source Projects 0 Sep 11th, 2006 1:05 AM
How to get current thread ID? myName C++ 2 Jul 6th, 2006 1:52 AM
dev c++ software, template problem cairo C++ 11 Jun 2nd, 2006 12:42 PM
What is your current status? pr0gm3r Coder's Corner Lounge 27 Aug 7th, 2005 5:14 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:38 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC