Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #29702
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2016-02-26 07:30 -0800 |
| References | (2 earlier) <f9846150-9602-4664-91d0-3ec40706eb01@googlegroups.com> <eaafc9ed-aee8-4a63-9b80-bd836e66252f@googlegroups.com> <2f6c8a08-a15b-439d-afe8-211824b13621@googlegroups.com> <b3e46030-3ec9-40bc-b801-ad5b18f0d3ac@googlegroups.com> <7a00760a-23c5-45eb-8694-f1c04037c01f@googlegroups.com> |
| Message-ID | <31643adf-d609-488c-9aad-dae54bcf32a5@googlegroups.com> (permalink) |
| Subject | Re: Exhausting link pairs between nodes using math.rand in a uniform network. |
| From | jonas.thornvall@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>
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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