• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting the object variables in loop only if a condition occurs

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I initialized the three variables(best, bestseq, Tms) of an object (o3). Later in a loop, I want to update these three variables only if a condition occurs( sm0 < best).
However what I see at the end is 'best' variable is updated correctly(only when sm0 < best) but the other two are updated at the every step of the loop.
I think there is a stupid mistake that I can't see since I am new in Java. Please I need an urgent help.






It is ridiculous that even though I use 'set' & 'get' methods below (setting the object only inside the if clause), "Tms for the new best"(which is updated correctly) and "Ultimate Tms"(updated somehow) are different. I guess, it is about Othree Class??




 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm afraid debugging this is above and beyond the call of our (volunteer) duty. I don't know (and can't tell) what the program is supposed to be doing overall, many of your variable names don't make any sense to me, and all that's before I wonder why this is recursive.

Put it in a debugger and step through it, looking at the values of these three variables to tell when they change. Eclipse will color them when they change so you don't even have to remember the old value.

The forum does really well at answering more specific questions. This is really more like "debug this for me".

rc
 
a elmas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree that it may all seem nonsense, but there is no way to simplify the codes because I don't know where the bug probably is.

The Recursive.anneal() is intended to optimize a set of sequences which is called 'dataset' here.

The sequences of this dataset is continuously and randomly changed(at each step they make a unique dataset) in Change.anneal() method until a parameter(defined by C and kk) is converged.

Each unique dataset have a score, 'sm0'.

I want to keep track of the best score, which is the minimum score of all unique datasets.

Well, the problem is that at the end I am able to see the best score(best) but not the corresponding dataset(bestseq).
To be more clear, I only wish to update 'best', 'bestseq' and 'Tms' when the current score(sm0) is lower than the best score so far(best).

The codes here are the translation from Matlab. I designed the algorithm originally in Matlab and needed to run it under Java to speed up. So the details may not make sense to Java users.
Maybe any experienced programmer might solve the problem by just looking into the object classes Othree and Ofive which I can't rely much.
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any experienced programmer CAN solve this problem. But if you don't have enough knowledge (or initiative) to put this through a debugger yourself, then it is unlikely to solve your overall programming problem. Recursion is not usually dashed off casually by a beginning programmer.

I'm not inclined to get started on it under these circumstances. Perhaps someone else will, although I seem to be the only one responding on this thread.

Good luck.

rc
 
a elmas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Believe me, if I have had that knowledge I would not exist on here. That is why I asked if it is an obvious issue of the Othree class.
Thanks anyway, I am still working on debugging.
 
a elmas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just fixed the problem. I was duplicating some objects instead of copying their values, so that the duplicates were also being set.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By "duplicating some objects instead of copying their values" I guess you mean that you were creating variables that refer to some object that another variable was already referring to, so that if you change the object through one variable, you'll also see the change when you look at the object through the other variable.

Note that it's important to make the distinction that variables are not objects - variables are references to objects. You're not "duplicating an object", you're just making some variable refer to the same object as another variable.

Good that you fixed the problem.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic