Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #29744

Re: Condition fullfilled to early "sometimes"

Newsgroups comp.lang.javascript
Date 2016-03-01 05:28 -0800
References <6ed0a1f8-d173-4de6-aff6-3590b34072d4@googlegroups.com> <65c8fd95-aefc-452e-ba2b-c4a94b1e7e1d@googlegroups.com> <87si0ajtuk.fsf@bsb.me.uk>
Message-ID <07c551f4-7b92-4e60-afbe-d0bd2ff62962@googlegroups.com> (permalink)
Subject Re: Condition fullfilled to early "sometimes"
From jonas.thornvall@gmail.com

Show all headers | View raw


Den tisdag 1 mars 2016 kl. 12:55:22 UTC+1 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
> 
> > Den tisdag 1 mars 2016 kl. 06:31:39 UTC+1 skrev jonas.t...@gmail.com:
> >> I've been looking at the code for two days so i am a bit crosseyed.
> >> If anyone could help me set the condition so the loop catch the last
> >> pair/pairs, it is kind of weird that it succeed sometimes and break
> >> to early and report fail others.
> >> 
> >> I would be very greatful if anyone can see why it break to early
> >> when return fail. Although a succes of uniform network is possible.
> >> 
> >> It is a minor bug due to some condition that i just not get.
> 
> How do you know it's minor?
Well by the fact i can see by visual inspection that i can do ***extras*** to correct it. But of course one would like the conditions correct. But i got so frustrated by the thing hangin in loops in browser all the time and it doesn't help the debugging. The fix will be two loops two check the requirments, yes i know that ain't pretty. But i do not think i can take two other days spent in loop... ;) 

> >> http://jt.node365.se/mydebug1.html
> >
> > The program creates search for uniform networks, that is x nodes each
> > with y links. Only a subset of permutations possible "easiest found
> > out with pen and paper". So to the left is the node and to the right
> > the nodes it links to.
> 
> If you'd like to learn about this topic, the words to search for are
> "regular graphs with degree y".  Even more specifically I suspect you want to
> generate connected regular graphs with some known degree.
> 
> <snip>
> > And here is the actual function doing it.
> >
> > function createLinks()
> > {
> >    var i = 0;
> >    var j = 0;
> >
> >    while(i < nodes)
> >    {
> > // This see so that links already generated accounted for if one link than j
> >       j = arr[i].nodelinks.length;
> >       stupid = nodes - 1;
> 
> More "global" variables.  Why give yourself the trouble?  What's so hard
> about a var or a let?

Thank's got that fixed that.
 
> >       temparr = new Array();
> >       while(j < links)
> >       {
> >          dublett = false;
> >          // Onlygenerate random values bigger than "i" else all links  exhausted
> >          if(i == 0)
> >          {
> >             aLink = Math.floor(Math.random() * (nodes - 1));
> >             aLink ++ ;
> >          }
> >          else
> >          {
> >             aLink = Math.floor(Math.random() * (stupid - i)) + i + 1;
> >          }
> 
> That "if" and the variable "stupid" are pointless.  Just write
>   Math.floor(Math.random() * (nodes - 1 - i)) + i + 1;

Thank's got that fixed that.

> But this can be simplified too, especially if you consider the next line:
> 
> >          if (aLink == nodes)aLink -- ;
I am aware but i don't seem to get it right without.

// Returns a random number between min (inclusive) and max (exclusive)
return Math.random() * (max - min) + min;

This seem to tell me i should write
 Math.floor(Math.random() * (nodes - i)) + i + 1;
But it will hang...

> which suggests the random selection of aLink is not being done
> correctly.  "Fixing" a previous mistake like this is not a good
> idea.  For one thing it will skew your random samples. 

No the random samples correct, otherwise the program wouldn't run to end.
 
> >          if (temparr[0] == null)
> >          {
> >             temparr[0] = aLink;
> >          }
> >          for(k = 0; k < arr[i].nodelinks.length; k ++ )
> >          {
> >             if(aLink == arr[i].nodelinks[k])
> >             {
> >                dublett = true;
> >             }
> >          }
> >          inmylist = false;
> >          var t = 0;
> >          for(var m = 0; m < temparr.length; m ++ )
> >          {
> >             if(temparr[m] == aLink)
> >             {
> >                inmylist = true;
> >             }
> >          }
> >          if (inmylist == false)
> >          {
> >             temparr[temparr.length] = aLink;
> >          
> >          }
> >          else
> >          {
> >             inmylist = false
> >          }
> >          scope = (nodes - 1) - i;
> >          if (temparr.length >= scope)
> >          {
> >             myboolean = false;
> >             return myboolean;
> >          }
> >        
> >          if(dublett == false && arr[aLink].nroflinks < links)
> >          {
> >             arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
> >             arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
> >             arr[i].nroflinks ++ ;
> >             arr[aLink].nroflinks ++ ;
> >             j ++ ;
> 
> Arrays support push().  And I think the only reason you need the object
> to track the number of links is because you are using globals and don't
> know how to empty the array between executions of this function.

That is true have not used push and do use arr=new Array to empty it between each function call in my search of regular graphs with deep y.

Thank's for your input.

> >          }
> >       }
> >       i ++ ;
> >    }
> >    myboolean = true;
> >    return myboolean;
> > } 
> 
> -- 
> Ben.

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Condition fullfilled to early "sometimes" jonas.thornvall@gmail.com - 2016-02-29 21:31 -0800
  Re: Condition fullfilled to early "sometimes" jonas.thornvall@gmail.com - 2016-03-01 01:03 -0800
    Re: Condition fullfilled to early "sometimes" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-01 11:55 +0000
      Re: Condition fullfilled to early "sometimes" jonas.thornvall@gmail.com - 2016-03-01 05:28 -0800
        Re: Condition fullfilled to early "sometimes" jonas.thornvall@gmail.com - 2016-03-01 07:49 -0800
          Re: Condition fullfilled to early "sometimes" jonas.thornvall@gmail.com - 2016-03-01 23:24 -0800
            Re: Condition fullfilled to early "sometimes" jonas.thornvall@gmail.com - 2016-03-02 00:41 -0800
              Re: Condition fullfilled to early "sometimes" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-02 10:43 +0000
                Re: Condition fullfilled to early "sometimes" jonas.thornvall@gmail.com - 2016-03-02 02:57 -0800
                Re: Condition fullfilled to early "sometimes" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-02 11:08 +0000
                Re: Condition fullfilled to early "sometimes" jonas.thornvall@gmail.com - 2016-03-02 05:53 -0800
                Re: Condition fullfilled to early "sometimes" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-02 16:27 +0000
                Re: Condition fullfilled to early "sometimes" jonas.thornvall@gmail.com - 2016-03-02 09:25 -0800
                Re: Condition fullfilled to early "sometimes" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-02 20:22 +0000
                Re: Condition fullfilled to early "sometimes" jonas.thornvall@gmail.com - 2016-03-02 02:59 -0800
                Re: Condition fullfilled to early "sometimes" jonas.thornvall@gmail.com - 2016-03-02 03:10 -0800
                Re: Condition fullfilled to early "sometimes" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-02 12:41 +0000
      Re: Condition fullfilled to early "sometimes" jonas.thornvall@gmail.com - 2016-03-02 01:42 -0800
  Re: Condition fullfilled to early "sometimes" John Harris <niam@jghnorth.org.uk.invalid> - 2016-03-01 10:47 +0000

csiph-web