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


Groups > comp.lang.javascript > #29707

Re: Exhausting link pairs between nodes using math.rand in a uniform network.

Newsgroups comp.lang.javascript
Date 2016-02-26 09:10 -0800
References (6 earlier) <7a00760a-23c5-45eb-8694-f1c04037c01f@googlegroups.com> <31643adf-d609-488c-9aad-dae54bcf32a5@googlegroups.com> <aa38623b-5538-4a49-a25f-0a4efe012165@googlegroups.com> <55293fc0-6397-4417-ae53-eca2cf64e7d8@googlegroups.com> <bc567223-a37a-4b68-9f74-1ab465a46895@googlegroups.com>
Message-ID <f544d63c-29f7-44ef-85b8-38f736eccf9b@googlegroups.com> (permalink)
Subject Re: Exhausting link pairs between nodes using math.rand in a uniform network.
From jonas.thornvall@gmail.com

Show all headers | View raw


Den fredag 26 februari 2016 kl. 16:58:51 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 26 februari 2016 kl. 16:41:54 UTC+1 skrev jonas.t...@gmail.com:
> > Den fredag 26 februari 2016 kl. 16:35:18 UTC+1 skrev jonas.t...@gmail.com:
> > > Den fredag 26 februari 2016 kl. 16:30:53 UTC+1 skrev jonas.t...@gmail.com:
> > > > Den fredag 26 februari 2016 kl. 15:05:11 UTC+1 skrev jonas.t...@gmail.com:
> > > > > Den fredag 26 februari 2016 kl. 14:49:52 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > Den fredag 26 februari 2016 kl. 14:27:20 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > > Den fredag 26 februari 2016 kl. 14:22:16 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > > > Den fredag 26 februari 2016 kl. 14:15:08 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > > > > Den fredag 26 februari 2016 kl. 14:13:07 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > > > > > Den fredag 26 februari 2016 kl. 13:51:05 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > > > > > > A short snippet to exhaust possible links.
> > > > > > > > > > > Solution is close so close i thought it was correct, but when i set to correct restriction upon the random, the  loop never end, and my understanding of firefox debugger to shallow to track down the loop error.
> > > > > > > > > > > 
> > > > > > > > > > > If anyone can see why it does not run thru with correct math rand restrictions tell me.
> > > > > > > > > > > 
> > > > > > > > > > > Sometimes one really would love a Turbo pascal debugger, because with it one could follow code execution and detect values that loop.
> > > > > > > > > > > 
> > > > > > > > > > > <script type="text/javascript">
> > > > > > > > > > > arr = new Array();nodes = 9; links = 4;
> > > > > > > > > > > for(k = 0; k < nodes; k ++ )
> > > > > > > > > > > {
> > > > > > > > > > >    arr[k] =   {  nroflinks : 0, nodelinks : "" };
> > > > > > > > > > > }
> > > > > > > > > > > createLinks();
> > > > > > > > > > > 
> > > > > > > > > > > function createLinks()
> > > > > > > > > > > {
> > > > > > > > > > >    i = 0;
> > > > > > > > > > >    j = 0;
> > > > > > > > > > >    temp = new Array();
> > > > > > > > > > >    
> > > > > > > > > > >    while(i < nodes)
> > > > > > > > > > >    {
> > > > > > > > > > >       //This see so that links already generated accounted for if one link than j=0 and so on.
> > > > > > > > > > >       j = arr[i].nroflinks;
> > > > > > > > > > >       while(j < links)
> > > > > > > > > > >       {
> > > > > > > > > > >          dublett = false;
> > > > > > > > > > >          //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > > > > > > > > > >          //Why?? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > > > > > > > > > >          aLink = Math.floor(Math.random() *nodes) ;
> > > > > > > > > > >          for(k = 0; k < temp.length; k ++ )
> > > > > > > > > > >          {
> > > > > > > > > > >             if(aLink == temp[k])
> > > > > > > > > > >             {
> > > > > > > > > > >                dublett = true; document.write("already in list " );
> > > > > > > > > > > 
> > > > > > > > > > >             }
> > > > > > > > > > >          }
> > > > > > > > > > >          
> > > > > > > > > > >          if(aLink == i){dublett=true;}
> > > > > > > > > > >          document.write(dublett,"New Link-->", aLink, "<br>");
> > > > > > > > > > >          if(dublett == false )
> > > > > > > > > > >          {
> > > > > > > > > > >             temp[j] = aLink;
> > > > > > > > > > >             arr[i].nodelinks += aLink + ",";
> > > > > > > > > > >             arr[aLink].nodelinks += i + ",";
> > > > > > > > > > >             document.write(i, "<--->", arr[i].nodelinks, "<br>");
> > > > > > > > > > >             arr[i].nroflinks ++ ;
> > > > > > > > > > >             arr[aLink].nroflinks ++ ;
> > > > > > > > > > >             j ++ ;
> > > > > > > > > > >          }
> > > > > > > > > > >       }
> > > > > > > > > > >       document.write("<P>" );
> > > > > > > > > > >    i++;
> > > > > > > > > > >    }
> > > > > > > > > > > }
> > > > > > > > > > > </script>
> > > > > > > > > > 
> > > > > > > > > > Well spotted an error, i probably need something else than storing links than in the string nodelinks. Because the comparisson do not account for links already written to node.
> > > > > > > > > > 
> > > > > > > > > > So rather than the string nodelinks temp arr should be nodelinks. But i have no idea how to declare an array within array.
> > > > > > > > > 
> > > > > > > > > I rephrase the question how do i make nodelinks an array rather than a string.
> > > > > > > > > 
> > > > > > > > > for(k = 0; k < nodes; k ++ )
> > > > > > > > > {
> > > > > > > > >    arr[k] =   {  nroflinks : 0, nodelinks : "" };
> > > > > > > > > }
> > > > > > > > 
> > > > > > > > That simple?
> > > > > > > > for(k = 0; k < nodes; k ++ )
> > > > > > > > {
> > > > > > > >    arr[k] =   {  nroflinks : 0, nodelinks : [] };
> > > > > > > > }
> > > > > > > 
> > > > > > > But how do i refer to it?
> > > > > > > 
> > > > > > > if (arr[i].nodelinks[j]==aLink){ } ?
> > > > > > 
> > > > > > But then you end up with something sick and convoluted, that is really hard to understand when you want to refer to an update an object. And personally i wonder why they simply did not go for multi dimensional arrays.
> > > > > > 
> > > > > > I mean this to just append an array slot and it is so hard to understand????
> > > > > > So we have an array with an attribute that nold nodelinks before i update it i want to check how many already storred. So i must refer to the same object once again? and see how many i already stored to move forward the array index of nodelinks to right position it just seem awkward.
> > > > > > 
> > > > > > Could it not just assume that nroflinks has the same arr[i] if not otherwise specified? It making it friggin hard to read.
> > > > > > 
> > > > > >   arr[i].nodelinks[arr[i].nroflinks] = aLink;
> > > > > > 
> > > > > > 
> > > > > > <script type="text/javascript">
> > > > > > arr = new Array();nodes = 9; links = 4;
> > > > > > 
> > > > > > for(k = 0; k < nodes; k ++ )
> > > > > > {
> > > > > >    arr[k] =   {  nroflinks : 0, nodelinks : [] };
> > > > > > }
> > > > > > 
> > > > > > createLinks();
> > > > > > 
> > > > > > function createLinks()
> > > > > > {
> > > > > >    i = 0;
> > > > > >    j = 0;
> > > > > >    temp = new Array();
> > > > > >    
> > > > > >    while(i < nodes)
> > > > > >    {
> > > > > >       //This see so that links already generated accounted for if one link than j=0 and so on.
> > > > > >       j = arr[i].nroflinks;
> > > > > >       while(j < links)
> > > > > >       {
> > > > > >          dublett = false;
> > > > > >          //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > > > > > //Why not correct????         aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > > > > >          aLink = Math.floor(Math.random() *nodes) ;
> > > > > >          for(k = 0; k < temp.length; k ++ )
> > > > > >          {
> > > > > >             if(aLink == temp[k])
> > > > > >             {
> > > > > >                dublett = true; document.write("already in list " );
> > > > > > 
> > > > > >             }
> > > > > >          }
> > > > > >          
> > > > > >          if(aLink == i){dublett=true;}
> > > > > >       
> > > > > >          if(dublett == false )
> > > > > >          {
> > > > > >               document.write(dublett,"New Link-->", aLink, "<br>");
> > > > > >             temp[j] = aLink;
> > > > > >             arr[i].nodelinks[arr[i].nroflinks] = aLink;
> > > > > >             arr[aLink].nodelinks[arr{aLink].nroflinks] += i;
> > > > > >             document.write(i, "<--->", arr[i].nodelinks, "<br>");
> > > > > >             arr[i].nroflinks ++ ;
> > > > > >             arr[aLink].nroflinks ++ ;
> > > > > >             j ++ ;
> > > > > >          }
> > > > > >       }
> > > > > >       document.write("<P>" );
> > > > > >    i++;
> > > > > >    }
> > > > > > }
> > > > > > </script>
> > > > > 
> > > > > but probably should use length...
> > > > 
> > > > Reconstruction almost there.
> > > > 
> > > > <script type="text/javascript">
> > > > arr = new Array();nodes = 9; links = 4;
> > > > 
> > > > for(k = 0; k < nodes; k ++ )
> > > > {
> > > >    arr[k] =   { nodelinks : [] };
> > > > }
> > > > 
> > > > createLinks();
> > > > 
> > > > function createLinks()
> > > > {
> > > >    i = 0;
> > > >    j = 0;
> > > > 
> > > >    
> > > >    while(i < nodes)
> > > >    {
> > > >       //This see so that links already generated accounted for if one link than j=0 and so on.
> > > >       j=arr[i].nodelinks.length;
> > > >       while(j < links)
> > > >       {
> > > >          dublett = false;
> > > >          //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > > > //Why not correct????         aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > > >          aLink = Math.floor(Math.random() *nodes) ;
> > > >          for(k = 0; k < arr[i].nodelinks.length; k ++ )
> > > >          {
> > > >             if(aLink == arr[i].nodelinks[k])
> > > >             {
> > > >                dublett = true; document.write("already in list " );
> > > >             }
> > > >          }
> > > >          
> > > >          if(aLink == i){dublett=true;}
> > > >          document.write(i,"...",dublett,"Link-->", aLink, "<br>");
> > > >          if(dublett == false )
> > > >          {
> > > >             arr[i].nodelinks[arr.length] = aLink;
> > > >             arr[aLink].nodelinks[arr.length] = i;
> > > >             j ++ ;
> > > >          }
> > > >       }
> > > >      document.write(arr[i].nodelinks, "<br>");
> > > >    i++;
> > > >    }
> > > > }
> > > > </script>
> > > 
> > > Did it?
> > > <script type="text/javascript">
> > > arr = new Array();nodes = 9; links = 4;
> > > 
> > > for(k = 0; k < nodes; k ++ )
> > > {
> > >    arr[k] =   { nodelinks : [] };
> > > }
> > > 
> > > createLinks();
> > > 
> > > function createLinks()
> > > {
> > >    i = 0;
> > >    j = 0;
> > > 
> > >    
> > >    while(i < nodes)
> > >    {
> > >       //This see so that links already generated accounted for if one link than j=0 and so on.
> > >       j=arr[i].nodelinks.length;
> > >       while(j < links)
> > >       {
> > >          dublett = false;
> > >          //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > > //Why not correct????         aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > >          aLink = Math.floor(Math.random() *nodes) ;
> > >          for(k = 0; k < arr[i].nodelinks.length; k ++ )
> > >          {
> > >             if(aLink == arr[i].nodelinks[k])
> > >             {
> > >                dublett = true; document.write("already in list " );
> > >             }
> > >          }
> > >          if(aLink == i){dublett=true;}
> > >       
> > >          document.write(i,"...",dublett,"Link-->", aLink, "<br>");
> > >          if(dublett == false )
> > >          {
> > >             arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
> > >             arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
> > >             j ++ ;
> > >          }
> > >       }
> > >      document.write(arr[i].nodelinks, "<br>");
> > >    i++;
> > >    }
> > > }
> > > </script>
> > 
> > Fixed the math.rand bug, now it will do many nodes and many link multiples.
> > 
> > <script type="text/javascript">
> > arr = new Array();nodes = 9; links = 4;
> > 
> > for(k = 0; k < nodes; k ++ )
> > {
> >    arr[k] =   { nodelinks : [] };
> > }
> > 
> > createLinks();
> > 
> > function createLinks()
> > {
> >    i = 0;
> >    j = 0;
> > 
> >    
> >    while(i < nodes)
> >    {
> >       //This see so that links already generated accounted for if one link than j=0 and so on.
> >       j=arr[i].nodelinks.length;
> >       while(j < links)
> >       {
> >          dublett = false;
> >          //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> >          if(i==0){aLink = Math.floor(Math.random() * (nodes - i)) + i;}
> >          else {aLink = Math.floor(Math.random() *nodes);}
> >          for(k = 0; k < arr[i].nodelinks.length; k ++ )
> >          {
> >             if(aLink == arr[i].nodelinks[k])
> >             {
> >                dublett = true; document.write("already in list " );
> >             }
> >          }
> >          if(aLink == i){dublett=true;}
> >       
> >          document.write(i,"...",dublett,"Link-->", aLink, "<br>");
> >          if(dublett == false )
> >          {
> >             arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
> >             arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
> >             j ++ ;
> >          }
> >       }
> >      document.write(arr[i].nodelinks, "<br>");
> >    i++;
> >    }
> > }
> > </script>
> 
> oops rushed it.
> <script type="text/javascript">
> arr = new Array();nodes = 4; links = 3;
> 
> for(k = 0; k < nodes; k ++ )
> {
>    arr[k] =   { nodelinks : [] };
> }
> 
> createLinks();
> 
> function createLinks()
> {
>    i = 0;
>    j = 0;
> 
>    
>    while(i < nodes)
>    {
>       //This see so that links already generated accounted for if one link than j=0 and so on.
>       j=arr[i].nodelinks.length;
>       while(j < links)
>       {
>          dublett = false;
>          //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
>          if(i==0){ aLink = Math.floor(Math.random() *nodes);}
>          else {aLink = Math.floor(Math.random() * (nodes - i)) + i;}
>          for(k = 0; k < arr[i].nodelinks.length; k ++ )
>          {
>             if(aLink == arr[i].nodelinks[k])
>             {
>                dublett = true; document.write(i," already in list " );
>             }
>          }
>          if(aLink == i){dublett=true;}
>       
>          document.write(dublett," Link-->", aLink, "<br>");
>          if(dublett == false )
>          {
>             arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
>             arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
>             j ++ ;
>          }
>       }
>      document.write(arr[i].nodelinks, "<br>");
>    i++;
>    }
> }
> </script>

Removed the counter at each node but it is obvious that one need to check it..

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


Thread

Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 04:50 -0800
  Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 05:13 -0800
    Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 05:15 -0800
      Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 05:22 -0800
        Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 05:27 -0800
          Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 05:49 -0800
            Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 06:05 -0800
              Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 07:30 -0800
                Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 07:35 -0800
                Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 07:41 -0800
                Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 07:58 -0800
                Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 09:10 -0800
                Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 09:36 -0800
                Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 10:42 -0800
  Re: Exhausting link pairs between nodes using math.rand in a uniform network. "Chris M. Thomasson" <nospam@no-spam.ws> - 2016-02-26 12:13 -0800
    Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 14:52 -0800
      Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-27 13:27 -0800
      Re: Exhausting link pairs between nodes using math.rand in a uniform network. Luuk <luuk@invalid.lan> - 2016-02-28 17:36 +0100
        Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-29 11:24 -0800
          Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-29 11:58 -0800
            Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-29 13:52 -0800

csiph-web