Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #29739 > unrolled thread
| Started by | jonas.thornvall@gmail.com |
|---|---|
| First post | 2016-02-29 21:31 -0800 |
| Last post | 2016-03-01 10:47 +0000 |
| Articles | 19 — 3 participants |
Back to article view | Back to comp.lang.javascript
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
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2016-02-29 21:31 -0800 |
| Subject | Condition fullfilled to early "sometimes" |
| Message-ID | <6ed0a1f8-d173-4de6-aff6-3590b34072d4@googlegroups.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. http://jt.node365.se/mydebug1.html
[toc] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2016-03-01 01:03 -0800 |
| Message-ID | <65c8fd95-aefc-452e-ba2b-c4a94b1e7e1d@googlegroups.com> |
| In reply to | #29739 |
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.
>
> 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.
When you run new network, sometimes it is full every node have x links, you create a uniform network. But often ir reports fail the links was exhausted and you stuck into a loop, that i fortunatily have the conditions to break.
But it *sometimes* break to early when there is still one or two pairs that would had worked. Not it is easy to make a fix for those, but it certainly would be more beautiful setting the correct condition.
Here is sample output and as you can see there is no reason to not create the last pair, the link is not a copy it should be created but condition somehow wrong *sometimes*.
Hurray failed generate network ***not quite if single pair two nodes missing
0'st NODE Links-> 7,3,5
1'st NODE Links-> 4,6,3
2'st NODE Links-> 5,9,3
3'st NODE Links-> 0,1,2
4'st NODE Links-> 1,8,5
5'st NODE Links-> 0,2,4
6'st NODE Links-> 1,7,9
7'st NODE Links-> 0,6,8
8'st NODE Links-> 4,7
9'st NODE Links-> 2,6
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;
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;
}
if (aLink == nodes)aLink -- ;
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 ++ ;
}
}
i ++ ;
}
myboolean = true;
return myboolean;
}
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-03-01 11:55 +0000 |
| Message-ID | <87si0ajtuk.fsf@bsb.me.uk> |
| In reply to | #29740 |
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?
>> 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?
> 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;
But this can be simplified too, especially if you consider the next line:
> if (aLink == nodes)aLink -- ;
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.
> 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.
> }
> }
> i ++ ;
> }
> myboolean = true;
> return myboolean;
> }
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2016-03-01 05:28 -0800 |
| Message-ID | <07c551f4-7b92-4e60-afbe-d0bd2ff62962@googlegroups.com> |
| In reply to | #29743 |
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.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2016-03-01 07:49 -0800 |
| Message-ID | <85aadccc-54fc-4136-a43b-8192fafcaf68@googlegroups.com> |
| In reply to | #29744 |
Den tisdag 1 mars 2016 kl. 14:28:49 UTC+1 skrev jonas.t...@gmail.com:
> 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.
If anyone have a clue about what is wrong with condition tell, because tomorrow i do a hack and it won't be pretty ;)
"Well feel free to show how random min max work also"
<HTML><BODY onLoad=init();>
<form name="network" onsubmit="init(); return false;" onSubmit>
Links:<input name="linkval" value="3" size="7" type="text"><br>
Multiple:<input name="lmult" value="3" size="3" type="text"><br>
Nodes: <input name="nodeval" value="" size="5" type="text" disabled><br>
<input type=submit name="network" value="NEW NETWORK"><br>
<textarea name="output" rows="100" cols="60"></textarea>
</form>
</BODY></HTML>
<script type="text/javascript">
function init()
{
links = document.network.linkval.value * 1;
multiple = document.network.lmult.value * 1;
nodes = (links * multiple) + 1;
document.network.nodeval.value = nodes;
arr = new Array();
myboolean = false;
while(myboolean == false)
{
createarr();
myboolean = createLinks();
}
for (var z = 0; z < nodes; z ++ )
{
document.network.output.value += z + "'st NODE Links-> "+arr[z].nodelinks+"\n";
}
}
function createarr()
{
for(k = 0; k < nodes; k ++ )
{
arr[k] =
{
nodelinks : [], nroflinks : 0
}
;
}
}
function createLinks()
{
document.network.output.value = "";
var i = 0;
var j = 0;
// document.network.output.value += "[***START NODE***->0 \n";
while(i < nodes)
{
// if(i < nodes - 1) document.network.output.value += "LINKS TO NODE -> " + arr[i].nodelinks + "\n\n";
j = arr[i].nodelinks.length;
temparr = new Array();
while(j < links)
{
dublett = false;
// Only have to generate random values that is bigger than "i" otherwise node full / exhausted
aLink = Math.floor(Math.random() * (nodes - 1 - i)) + i + 1;
// document.network.output.value += "New rand:" + aLink + " I=" + i + "\n";
if (temparr[0] == null)
{
temparr[0] = aLink;
}
for(k = 0; k < arr[i].nodelinks.length; k ++ )
{
if(aLink == arr[i].nodelinks[k])
{
dublett = true;
}
}
var t = 0;
inmylist = false;
for(var m = 0; m < temparr.length; m ++ )
{
if(temparr[m] == aLink)
{
inmylist = true;
// document.network.output.value += inmylist + " Kilroy was here , nothing added to list [" + temparr + "\n";
}
}
if (inmylist == false)
{
temparr[temparr.length] = aLink;
// document.network.output.value += "Added to mylist" + temparr + "\n";
}
scope = (nodes - 1) - i;
// document.network.output.value += "Break if TRUE " + temparr.length + ">=" + scope + "\n";
if (temparr.length >= scope)
{
document.network.output.value += "Hurray failed generate ***not quite if single pair two nodes missing \n";
myboolean = false;
return myboolean;
}
// document.network.output.value += i + "]" + " Linked-->" + aLink + " " + dublett + "\n";
if(dublett == false && arr[aLink].nroflinks < links)
{
// document.network.output.value += "[ADDED LINK] " + aLink + "\n\n";
arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
arr[i].nroflinks ++ ;
arr[aLink].nroflinks ++ ;
j ++ ;
}
}
// document.network.output.value += "***FINISHED NODE*** " + i + " Links =" + arr[i].nodelinks + "\n\n";
i ++ ;
// document.network.output.value += "[***START NODE***-> " + i + " ";
}
document.network.output.value += "Hurray succeded to generate network!!!\n";
myboolean = true;
return myboolean;
}
</script>
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2016-03-01 23:24 -0800 |
| Message-ID | <5cb9c676-5153-4676-928b-355b386fe1ca@googlegroups.com> |
| In reply to | #29746 |
Den tisdag 1 mars 2016 kl. 16:49:49 UTC+1 skrev jonas.t...@gmail.com:
> Den tisdag 1 mars 2016 kl. 14:28:49 UTC+1 skrev jonas.t...@gmail.com:
> > 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.
>
> If anyone have a clue about what is wrong with condition tell, because tomorrow i do a hack and it won't be pretty ;)
> "Well feel free to show how random min max work also"
>
> <HTML><BODY onLoad=init();>
> <form name="network" onsubmit="init(); return false;" onSubmit>
> Links:<input name="linkval" value="3" size="7" type="text"><br>
> Multiple:<input name="lmult" value="3" size="3" type="text"><br>
> Nodes: <input name="nodeval" value="" size="5" type="text" disabled><br>
> <input type=submit name="network" value="NEW NETWORK"><br>
> <textarea name="output" rows="100" cols="60"></textarea>
> </form>
>
> </BODY></HTML>
>
> <script type="text/javascript">
>
> function init()
> {
> links = document.network.linkval.value * 1;
> multiple = document.network.lmult.value * 1;
> nodes = (links * multiple) + 1;
> document.network.nodeval.value = nodes;
> arr = new Array();
> myboolean = false;
> while(myboolean == false)
> {
> createarr();
> myboolean = createLinks();
> }
> for (var z = 0; z < nodes; z ++ )
> {
> document.network.output.value += z + "'st NODE Links-> "+arr[z].nodelinks+"\n";
> }
> }
>
> function createarr()
> {
> for(k = 0; k < nodes; k ++ )
> {
> arr[k] =
> {
> nodelinks : [], nroflinks : 0
> }
> ;
> }
> }
>
> function createLinks()
> {
> document.network.output.value = "";
> var i = 0;
> var j = 0;
> // document.network.output.value += "[***START NODE***->0 \n";
> while(i < nodes)
> {
> // if(i < nodes - 1) document.network.output.value += "LINKS TO NODE -> " + arr[i].nodelinks + "\n\n";
> j = arr[i].nodelinks.length;
> temparr = new Array();
> while(j < links)
> {
> dublett = false;
> // Only have to generate random values that is bigger than "i" otherwise node full / exhausted
> aLink = Math.floor(Math.random() * (nodes - 1 - i)) + i + 1;
> // document.network.output.value += "New rand:" + aLink + " I=" + i + "\n";
> if (temparr[0] == null)
> {
> temparr[0] = aLink;
> }
> for(k = 0; k < arr[i].nodelinks.length; k ++ )
> {
> if(aLink == arr[i].nodelinks[k])
> {
> dublett = true;
> }
> }
>
> var t = 0;
> inmylist = false;
> for(var m = 0; m < temparr.length; m ++ )
> {
> if(temparr[m] == aLink)
> {
> inmylist = true;
> // document.network.output.value += inmylist + " Kilroy was here , nothing added to list [" + temparr + "\n";
>
> }
> }
> if (inmylist == false)
> {
> temparr[temparr.length] = aLink;
> // document.network.output.value += "Added to mylist" + temparr + "\n";
> }
>
> scope = (nodes - 1) - i;
> // document.network.output.value += "Break if TRUE " + temparr.length + ">=" + scope + "\n";
> if (temparr.length >= scope)
> {
> document.network.output.value += "Hurray failed generate ***not quite if single pair two nodes missing \n";
> myboolean = false;
> return myboolean;
> }
> // document.network.output.value += i + "]" + " Linked-->" + aLink + " " + dublett + "\n";
> if(dublett == false && arr[aLink].nroflinks < links)
> {
> // document.network.output.value += "[ADDED LINK] " + aLink + "\n\n";
> arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
> arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
> arr[i].nroflinks ++ ;
> arr[aLink].nroflinks ++ ;
> j ++ ;
> }
> }
>
> // document.network.output.value += "***FINISHED NODE*** " + i + " Links =" + arr[i].nodelinks + "\n\n";
> i ++ ;
> // document.network.output.value += "[***START NODE***-> " + i + " ";
> }
> document.network.output.value += "Hurray succeded to generate network!!!\n";
> myboolean = true;
> return myboolean;
> }
> </script>
Ok hack it is.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2016-03-02 00:41 -0800 |
| Message-ID | <af964e6d-57d4-484c-a2b8-ecdecab8dd08@googlegroups.com> |
| In reply to | #29756 |
Den onsdag 2 mars 2016 kl. 08:25:04 UTC+1 skrev jonas.t...@gmail.com:
> Den tisdag 1 mars 2016 kl. 16:49:49 UTC+1 skrev jonas.t...@gmail.com:
> > Den tisdag 1 mars 2016 kl. 14:28:49 UTC+1 skrev jonas.t...@gmail.com:
> > > 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.
> >
> > If anyone have a clue about what is wrong with condition tell, because tomorrow i do a hack and it won't be pretty ;)
> > "Well feel free to show how random min max work also"
> >
> > <HTML><BODY onLoad=init();>
> > <form name="network" onsubmit="init(); return false;" onSubmit>
> > Links:<input name="linkval" value="3" size="7" type="text"><br>
> > Multiple:<input name="lmult" value="3" size="3" type="text"><br>
> > Nodes: <input name="nodeval" value="" size="5" type="text" disabled><br>
> > <input type=submit name="network" value="NEW NETWORK"><br>
> > <textarea name="output" rows="100" cols="60"></textarea>
> > </form>
> >
> > </BODY></HTML>
> >
> > <script type="text/javascript">
> >
> > function init()
> > {
> > links = document.network.linkval.value * 1;
> > multiple = document.network.lmult.value * 1;
> > nodes = (links * multiple) + 1;
> > document.network.nodeval.value = nodes;
> > arr = new Array();
> > myboolean = false;
> > while(myboolean == false)
> > {
> > createarr();
> > myboolean = createLinks();
> > }
> > for (var z = 0; z < nodes; z ++ )
> > {
> > document.network.output.value += z + "'st NODE Links-> "+arr[z].nodelinks+"\n";
> > }
> > }
> >
> > function createarr()
> > {
> > for(k = 0; k < nodes; k ++ )
> > {
> > arr[k] =
> > {
> > nodelinks : [], nroflinks : 0
> > }
> > ;
> > }
> > }
> >
> > function createLinks()
> > {
> > document.network.output.value = "";
> > var i = 0;
> > var j = 0;
> > // document.network.output.value += "[***START NODE***->0 \n";
> > while(i < nodes)
> > {
> > // if(i < nodes - 1) document.network.output.value += "LINKS TO NODE -> " + arr[i].nodelinks + "\n\n";
> > j = arr[i].nodelinks.length;
> > temparr = new Array();
> > while(j < links)
> > {
> > dublett = false;
> > // Only have to generate random values that is bigger than "i" otherwise node full / exhausted
> > aLink = Math.floor(Math.random() * (nodes - 1 - i)) + i + 1;
> > // document.network.output.value += "New rand:" + aLink + " I=" + i + "\n";
> > if (temparr[0] == null)
> > {
> > temparr[0] = aLink;
> > }
> > for(k = 0; k < arr[i].nodelinks.length; k ++ )
> > {
> > if(aLink == arr[i].nodelinks[k])
> > {
> > dublett = true;
> > }
> > }
> >
> > var t = 0;
> > inmylist = false;
> > for(var m = 0; m < temparr.length; m ++ )
> > {
> > if(temparr[m] == aLink)
> > {
> > inmylist = true;
> > // document.network.output.value += inmylist + " Kilroy was here , nothing added to list [" + temparr + "\n";
> >
> > }
> > }
> > if (inmylist == false)
> > {
> > temparr[temparr.length] = aLink;
> > // document.network.output.value += "Added to mylist" + temparr + "\n";
> > }
> >
> > scope = (nodes - 1) - i;
> > // document.network.output.value += "Break if TRUE " + temparr.length + ">=" + scope + "\n";
> > if (temparr.length >= scope)
> > {
> > document.network.output.value += "Hurray failed generate ***not quite if single pair two nodes missing \n";
> > myboolean = false;
> > return myboolean;
> > }
> > // document.network.output.value += i + "]" + " Linked-->" + aLink + " " + dublett + "\n";
> > if(dublett == false && arr[aLink].nroflinks < links)
> > {
> > // document.network.output.value += "[ADDED LINK] " + aLink + "\n\n";
> > arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
> > arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
> > arr[i].nroflinks ++ ;
> > arr[aLink].nroflinks ++ ;
> > j ++ ;
> > }
> > }
> >
> > // document.network.output.value += "***FINISHED NODE*** " + i + " Links =" + arr[i].nodelinks + "\n\n";
> > i ++ ;
> > // document.network.output.value += "[***START NODE***-> " + i + " ";
> > }
> > document.network.output.value += "Hurray succeded to generate network!!!\n";
> > myboolean = true;
> > return myboolean;
> > }
> > </script>
>
> Ok hack it is.
Phewww http://jt.node365.se/mydebug3.html
Last minute rescue!!! At least i have not found any incorrect reports. I think it breaks and decide correct for any generated network.
<HTML><BODY onLoad=init();>
<form name="network" onsubmit="init(); return false;" onSubmit>
Links:<input name="linkval" value="3" size="7" type="text"><br>
Multiple:<input name="lmult" value="3" size="3" type="text"><br>
Nodes: <input name="nodeval" value="" size="5" type="text" disabled><br>
<input type=submit name="network" value="NEW NETWORK"><br>
<textarea name="output" rows="100" cols="60"></textarea>
</form>
</BODY></HTML>
<script type="text/javascript">
function init()
{
links = document.network.linkval.value * 1;
multiple = document.network.lmult.value * 1;
nodes = (links * multiple) + 1;
document.network.nodeval.value = nodes;
arr = new Array();
myboolean = false;
// while(myboolean == false)
// {
createarr();
myboolean = createLinks();
// }
for (var z = 0; z < nodes; z ++ )
{
document.network.output.value += z + "'st NODE Links-> "+arr[z].nodelinks+"\n";
}
}
function createarr()
{
for(k = 0; k < nodes; k ++ )
{
arr[k] =
{
nodelinks : [], nroflinks : 0
}
;
}
}
function createLinks()
{
document.network.output.value = "";
var i = 0;
var j = 0;
// document.network.output.value += "[***START NODE***->0 \n";
while(i < nodes-1)
{
// if(i < nodes - 1) document.network.output.value += "LINKS TO NODE -> " + arr[i].nodelinks + "\n\n";
j = arr[i].nodelinks.length;
temparr = new Array();
while(j < links)
{
dublett = false;
// Only have to generate random values that is bigger than "i" otherwise node full / exhausted
aLink = Math.floor(Math.random() * (nodes - 1 - i)) + i + 1;
// document.network.output.value += "New rand:" + aLink + " I=" + i + "\n";
if (temparr[0] == null)
{
temparr[0] = aLink;
}
for(k = 0; k < arr[i].nodelinks.length; k ++ )
{
if(aLink == arr[i].nodelinks[k])
{
dublett = true;
}
}
// document.network.output.value += i + "]" + " Linked-->" + aLink + " " + dublett + "\n";
//if(dublett == false && arr[aLink].nroflinks < links)
if(dublett == false && arr[aLink].nodelinks.length < links)
{
// document.network.output.value += "[ADDED LINK] " + aLink + "\n\n";
arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
j ++ ;
}
// var t = 0;
inmylist = false;
for(var m = 0; m < temparr.length; m ++ )
{
if(temparr[m] == aLink)
{
inmylist = true;
// document.network.output.value += inmylist + " Kilroy was here , nothing added to list [" + temparr + "\n";
}
}
if (inmylist == false)
{
temparr[temparr.length] = aLink;
// document.network.output.value += "Added to mylist" + temparr + "\n";
}
scope = (nodes-1) - i;
// document.network.output.value += "Break if TRUE " + temparr.length + ">=" + scope + "\n";
if (temparr.length == scope)
{
document.network.output.value += "Hurray failed generate ***not quite if single pair two nodes missing \n";
myboolean = false;
return myboolean;
}
}
// document.network.output.value += "***FINISHED NODE*** " + i + " Links =" + arr[i].nodelinks + "\n\n";
i ++ ;
// document.network.output.value += "[***START NODE***-> " + i + " ";
}
if(arr[i].nodelinks.length < links){
myboolean=false;
return myboolean;
} else {
document.network.output.value += "Hurray succeded to generate network!!!\n";
myboolean = true;
return myboolean;}
}
</script>
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-03-02 10:43 +0000 |
| Message-ID | <8760x5jh1y.fsf@bsb.me.uk> |
| In reply to | #29757 |
jonas.thornvall@gmail.com writes:
<snip>
Why did you post all those old lines? It's better to cut your messages
down.
> Phewww http://jt.node365.se/mydebug3.html
>
> Last minute rescue!!! At least i have not found any incorrect
> reports. I think it breaks and decide correct for any generated
> network.
Not as far as I can see. One sample output:
$ nodejs mydebug3.js
Hurray **failed** generate regular graph
[ { nodelinks: [ 4, 2 ], nroflinks: 0 },
{ nodelinks: [ 2, 4 ], nroflinks: 0 },
{ nodelinks: [ 0, 1 ], nroflinks: 0 },
{ nodelinks: [], nroflinks: 0 },
{ nodelinks: [ 0, 1 ], nroflinks: 0 } ]
<snip>
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2016-03-02 02:57 -0800 |
| Message-ID | <7d8ee7de-9921-4b79-ac1e-b7492abae36a@googlegroups.com> |
| In reply to | #29760 |
Den onsdag 2 mars 2016 kl. 11:44:05 UTC+1 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
>
> <snip>
> Why did you post all those old lines? It's better to cut your messages
> down.
>
> > Phewww http://jt.node365.se/mydebug3.html
> >
> > Last minute rescue!!! At least i have not found any incorrect
> > reports. I think it breaks and decide correct for any generated
> > network.
>
> Not as far as I can see. One sample output:
>
> $ nodejs mydebug3.js
> Hurray **failed** generate regular graph
>
> [ { nodelinks: [ 4, 2 ], nroflinks: 0 },
> { nodelinks: [ 2, 4 ], nroflinks: 0 },
> { nodelinks: [ 0, 1 ], nroflinks: 0 },
> { nodelinks: [], nroflinks: 0 },
> { nodelinks: [ 0, 1 ], nroflinks: 0 } ]
>
> <snip>
> --
> Ben.
I am not sure what you mean?
It can't possibly be a uniform graph, if you don't make a chain?
The last one can't possibly link to itself, it must be a chain?
The program works.
http://jt.node365.se/nodes12.html
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-03-02 11:08 +0000 |
| Message-ID | <87ziuhi1d0.fsf@bsb.me.uk> |
| In reply to | #29761 |
jonas.thornvall@gmail.com writes:
> Den onsdag 2 mars 2016 kl. 11:44:05 UTC+1 skrev Ben Bacarisse:
>> jonas.thornvall@gmail.com writes:
>>
>> <snip>
>> Why did you post all those old lines? It's better to cut your messages
>> down.
>>
>> > Phewww http://jt.node365.se/mydebug3.html
>> >
>> > Last minute rescue!!! At least i have not found any incorrect
>> > reports. I think it breaks and decide correct for any generated
>> > network.
>>
>> Not as far as I can see. One sample output:
>>
>> $ nodejs mydebug3.js
>> Hurray **failed** generate regular graph
>>
>> [ { nodelinks: [ 4, 2 ], nroflinks: 0 },
>> { nodelinks: [ 2, 4 ], nroflinks: 0 },
>> { nodelinks: [ 0, 1 ], nroflinks: 0 },
>> { nodelinks: [], nroflinks: 0 },
>> { nodelinks: [ 0, 1 ], nroflinks: 0 } ]
>>
>> <snip>
>> --
>> Ben.
>
> I am not sure what you mean?
Just that with values of linkval == 2 and lmult == 2 I get output as
above that appears to report failure.
> It can't possibly be a uniform graph, if you don't make a chain?
> The last one can't possibly link to itself, it must be a chain?
I don't know what the program is trying to do, so I don't know if this
output is correct or not. I don't even know if the input values are
valid. You are likely to get better help if you explain what you are
trying to do (and that would mean using the standard terms).
> The program works.
Great.
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2016-03-02 05:53 -0800 |
| Message-ID | <ca64207e-1c1e-4ef2-bbd2-877ba87b1862@googlegroups.com> |
| In reply to | #29763 |
Den onsdag 2 mars 2016 kl. 12:08:17 UTC+1 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
>
> > Den onsdag 2 mars 2016 kl. 11:44:05 UTC+1 skrev Ben Bacarisse:
> >> jonas.thornvall@gmail.com writes:
> >>
> >> <snip>
> >> Why did you post all those old lines? It's better to cut your messages
> >> down.
> >>
> >> > Phewww http://jt.node365.se/mydebug3.html
> >> >
> >> > Last minute rescue!!! At least i have not found any incorrect
> >> > reports. I think it breaks and decide correct for any generated
> >> > network.
> >>
> >> Not as far as I can see. One sample output:
> >>
> >> $ nodejs mydebug3.js
> >> Hurray **failed** generate regular graph
> >>
> >> [ { nodelinks: [ 4, 2 ], nroflinks: 0 },
> >> { nodelinks: [ 2, 4 ], nroflinks: 0 },
> >> { nodelinks: [ 0, 1 ], nroflinks: 0 },
> >> { nodelinks: [], nroflinks: 0 },
> >> { nodelinks: [ 0, 1 ], nroflinks: 0 } ]
> >>
> >> <snip>
> >> --
> >> Ben.
> >
> > I am not sure what you mean?
>
> Just that with values of linkval == 2 and lmult == 2 I get output as
> above that appears to report failure.
>
> > It can't possibly be a uniform graph, if you don't make a chain?
> > The last one can't possibly link to itself, it must be a chain?
>
> I don't know what the program is trying to do, so I don't know if this
> output is correct or not. I don't even know if the input values are
> valid. You are likely to get better help if you explain what you are
> trying to do (and that would mean using the standard terms).
>
> > The program works.
>
> Great.
>
> --
> Ben.
Well i said nothing about cycle length i just ordered because of simplicity but
The subsets all on the form links*multiple+1=nodes, i just thought it was handy when drawing all to all and looked nice. But of course i can do something where you can chose nodes and links free.
But these is regular graphs, all nodes have same number of links, but as you hint maybe just a subset of them?
0'st NODE Links-> 4,5,1
1'st NODE Links-> 0,2,6
2'st NODE Links-> 1,9,4
3'st NODE Links-> 9,5,8
4'st NODE Links-> 0,2,9
5'st NODE Links-> 0,3,7
6'st NODE Links-> 1,8,7
7'st NODE Links-> 5,6,8
8'st NODE Links-> 3,6,7
9'st NODE Links-> 2,3,4
Another example
0 NODE Links-> 1,8,2
1 NODE Links-> 0,3,9
2 NODE Links-> 0,9,7
3 NODE Links-> 1,9,7
4 NODE Links-> 6,7,5
5 NODE Links-> 4,8,6
6 NODE Links-> 4,5,8
7 NODE Links-> 2,3,4
8 NODE Links-> 0,5,6
9 NODE Links-> 1,2,3
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-03-02 16:27 +0000 |
| Message-ID | <87ziughmkf.fsf@bsb.me.uk> |
| In reply to | #29768 |
jonas.thornvall@gmail.com writes:
> Den onsdag 2 mars 2016 kl. 12:08:17 UTC+1 skrev Ben Bacarisse:
>> jonas.thornvall@gmail.com writes:
>>
>> > Den onsdag 2 mars 2016 kl. 11:44:05 UTC+1 skrev Ben Bacarisse:
>> >> jonas.thornvall@gmail.com writes:
>> >>
>> >> <snip>
>> >> Why did you post all those old lines? It's better to cut your messages
>> >> down.
>> >>
>> >> > Phewww http://jt.node365.se/mydebug3.html
>> >> >
>> >> > Last minute rescue!!! At least i have not found any incorrect
>> >> > reports. I think it breaks and decide correct for any generated
>> >> > network.
>> >>
>> >> Not as far as I can see. One sample output:
>> >>
>> >> $ nodejs mydebug3.js
>> >> Hurray **failed** generate regular graph
>> >>
>> >> [ { nodelinks: [ 4, 2 ], nroflinks: 0 },
>> >> { nodelinks: [ 2, 4 ], nroflinks: 0 },
>> >> { nodelinks: [ 0, 1 ], nroflinks: 0 },
>> >> { nodelinks: [], nroflinks: 0 },
>> >> { nodelinks: [ 0, 1 ], nroflinks: 0 } ]
>> >>
>> >> <snip>
>> >> --
>> >> Ben.
>> >
>> > I am not sure what you mean?
>>
>> Just that with values of linkval == 2 and lmult == 2 I get output as
>> above that appears to report failure.
>>
>> > It can't possibly be a uniform graph, if you don't make a chain?
>> > The last one can't possibly link to itself, it must be a chain?
>>
>> I don't know what the program is trying to do, so I don't know if this
>> output is correct or not. I don't even know if the input values are
>> valid. You are likely to get better help if you explain what you are
>> trying to do (and that would mean using the standard terms).
>>
>> > The program works.
>>
>> Great.
>
> Well i said nothing about cycle length i just ordered because of
> simplicity but
>
> The subsets all on the form links*multiple+1=nodes, i just thought it
> was handy when drawing all to all and looked nice. But of course i can
> do something where you can chose nodes and links free.
>
> But these is regular graphs, all nodes have same number of links, but
> as you hint maybe just a subset of them?
>
> 0'st NODE Links-> 4,5,1
> 1'st NODE Links-> 0,2,6
> 2'st NODE Links-> 1,9,4
> 3'st NODE Links-> 9,5,8
> 4'st NODE Links-> 0,2,9
> 5'st NODE Links-> 0,3,7
> 6'st NODE Links-> 1,8,7
> 7'st NODE Links-> 5,6,8
> 8'st NODE Links-> 3,6,7
> 9'st NODE Links-> 2,3,4
What about:
Hurray **failed** generate regular graph
0'st NODE Links-> 3,9,7
1'st NODE Links-> 5,7,6
2'st NODE Links-> 9,6,8
3'st NODE Links-> 0,5,6
4'st NODE Links-> 9,5,7
5'st NODE Links-> 1,3,4
6'st NODE Links-> 1,2,3
7'st NODE Links-> 0,1,4
8'st NODE Links-> 2
9'st NODE Links-> 0,2,4
?
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2016-03-02 09:25 -0800 |
| Message-ID | <6a450017-e90b-48ca-8912-8d6db58d9b90@googlegroups.com> |
| In reply to | #29773 |
Den onsdag 2 mars 2016 kl. 17:27:55 UTC+1 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
>
> > Den onsdag 2 mars 2016 kl. 12:08:17 UTC+1 skrev Ben Bacarisse:
> >> jonas.thornvall@gmail.com writes:
> >>
> >> > Den onsdag 2 mars 2016 kl. 11:44:05 UTC+1 skrev Ben Bacarisse:
> >> >> jonas.thornvall@gmail.com writes:
> >> >>
> >> >> <snip>
> >> >> Why did you post all those old lines? It's better to cut your messages
> >> >> down.
> >> >>
> >> >> > Phewww http://jt.node365.se/mydebug3.html
> >> >> >
> >> >> > Last minute rescue!!! At least i have not found any incorrect
> >> >> > reports. I think it breaks and decide correct for any generated
> >> >> > network.
> >> >>
> >> >> Not as far as I can see. One sample output:
> >> >>
> >> >> $ nodejs mydebug3.js
> >> >> Hurray **failed** generate regular graph
> >> >>
> >> >> [ { nodelinks: [ 4, 2 ], nroflinks: 0 },
> >> >> { nodelinks: [ 2, 4 ], nroflinks: 0 },
> >> >> { nodelinks: [ 0, 1 ], nroflinks: 0 },
> >> >> { nodelinks: [], nroflinks: 0 },
> >> >> { nodelinks: [ 0, 1 ], nroflinks: 0 } ]
> >> >>
> >> >> <snip>
> >> >> --
> >> >> Ben.
> >> >
> >> > I am not sure what you mean?
> >>
> >> Just that with values of linkval == 2 and lmult == 2 I get output as
> >> above that appears to report failure.
> >>
> >> > It can't possibly be a uniform graph, if you don't make a chain?
> >> > The last one can't possibly link to itself, it must be a chain?
> >>
> >> I don't know what the program is trying to do, so I don't know if this
> >> output is correct or not. I don't even know if the input values are
> >> valid. You are likely to get better help if you explain what you are
> >> trying to do (and that would mean using the standard terms).
> >>
> >> > The program works.
> >>
> >> Great.
> >
> > Well i said nothing about cycle length i just ordered because of
> > simplicity but
> >
> > The subsets all on the form links*multiple+1=nodes, i just thought it
> > was handy when drawing all to all and looked nice. But of course i can
> > do something where you can chose nodes and links free.
> >
> > But these is regular graphs, all nodes have same number of links, but
> > as you hint maybe just a subset of them?
> >
> > 0'st NODE Links-> 4,5,1
> > 1'st NODE Links-> 0,2,6
> > 2'st NODE Links-> 1,9,4
> > 3'st NODE Links-> 9,5,8
> > 4'st NODE Links-> 0,2,9
> > 5'st NODE Links-> 0,3,7
> > 6'st NODE Links-> 1,8,7
> > 7'st NODE Links-> 5,6,8
> > 8'st NODE Links-> 3,6,7
> > 9'st NODE Links-> 2,3,4
>
> What about:
>
> Hurray **failed** generate regular graph
> 0'st NODE Links-> 3,9,7
> 1'st NODE Links-> 5,7,6
> 2'st NODE Links-> 9,6,8
> 3'st NODE Links-> 0,5,6
> 4'st NODE Links-> 9,5,7
> 5'st NODE Links-> 1,3,4
> 6'st NODE Links-> 1,2,3
> 7'st NODE Links-> 0,1,4
> 8'st NODE Links-> 2
> 9'st NODE Links-> 0,2,4
>
> ?
>
> --
> Ben.
I do not see what you mean there is only two free positions, "that is one pair".
You think it is alright they point back at eachother from node 8.
That is not a link in my opinions and no regular graph with 10 nodes was created.
Do you think so, doesn't a link run between two nodes?
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-03-02 20:22 +0000 |
| Message-ID | <87mvqghbp7.fsf@bsb.me.uk> |
| In reply to | #29774 |
jonas.thornvall@gmail.com writes: > Den onsdag 2 mars 2016 kl. 17:27:55 UTC+1 skrev Ben Bacarisse: >> > Den onsdag 2 mars 2016 kl. 12:08:17 UTC+1 skrev Ben Bacarisse: >> >> jonas.thornvall@gmail.com writes: <snip> >> >> > The program works. >> >> >> >> Great. <snip> >> What about: >> >> Hurray **failed** generate regular graph >> 0'st NODE Links-> 3,9,7 >> 1'st NODE Links-> 5,7,6 >> 2'st NODE Links-> 9,6,8 >> 3'st NODE Links-> 0,5,6 >> 4'st NODE Links-> 9,5,7 >> 5'st NODE Links-> 1,3,4 >> 6'st NODE Links-> 1,2,3 >> 7'st NODE Links-> 0,1,4 >> 8'st NODE Links-> 2 >> 9'st NODE Links-> 0,2,4 >> >> ? > > I do not see what you mean there is only two free positions, "that is one pair". > You think it is alright they point back at eachother from node 8. > > That is not a link in my opinions and no regular graph with 10 nodes was created. > > Do you think so, doesn't a link run between two nodes? I fear we are talking at cross purposes. You said your program works, but the output I showed looks wrong to me. Maybe I just don't know what the program is supposed to do. If the output is correct, I'll comment no further. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2016-03-02 02:59 -0800 |
| Message-ID | <e579f6a6-f33d-4b4f-84ff-60c8dbb2ce95@googlegroups.com> |
| In reply to | #29760 |
Den onsdag 2 mars 2016 kl. 11:44:05 UTC+1 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
>
> <snip>
> Why did you post all those old lines? It's better to cut your messages
> down.
>
> > Phewww http://jt.node365.se/mydebug3.html
> >
> > Last minute rescue!!! At least i have not found any incorrect
> > reports. I think it breaks and decide correct for any generated
> > network.
>
> Not as far as I can see. One sample output:
>
> $ nodejs mydebug3.js
> Hurray **failed** generate regular graph
>
> [ { nodelinks: [ 4, 2 ], nroflinks: 0 },
> { nodelinks: [ 2, 4 ], nroflinks: 0 },
> { nodelinks: [ 0, 1 ], nroflinks: 0 },
> { nodelinks: [], nroflinks: 0 },
> { nodelinks: [ 0, 1 ], nroflinks: 0 } ]
>
> <snip>
> --
> Ben.
Maybe you mean it did create a regular graph with 4 nodes?
But the program looks for regular graphs with x nodes in this case 5.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2016-03-02 03:10 -0800 |
| Message-ID | <03e0e9f1-3f08-4e9a-aa69-f87d45ba8e0b@googlegroups.com> |
| In reply to | #29762 |
Den onsdag 2 mars 2016 kl. 11:59:36 UTC+1 skrev jonas.t...@gmail.com:
> Den onsdag 2 mars 2016 kl. 11:44:05 UTC+1 skrev Ben Bacarisse:
> > jonas.thornvall@gmail.com writes:
> >
> > <snip>
> > Why did you post all those old lines? It's better to cut your messages
> > down.
> >
> > > Phewww http://jt.node365.se/mydebug3.html
> > >
> > > Last minute rescue!!! At least i have not found any incorrect
> > > reports. I think it breaks and decide correct for any generated
> > > network.
> >
> > Not as far as I can see. One sample output:
> >
> > $ nodejs mydebug3.js
> > Hurray **failed** generate regular graph
> >
> > [ { nodelinks: [ 4, 2 ], nroflinks: 0 },
> > { nodelinks: [ 2, 4 ], nroflinks: 0 },
> > { nodelinks: [ 0, 1 ], nroflinks: 0 },
> > { nodelinks: [], nroflinks: 0 },
> > { nodelinks: [ 0, 1 ], nroflinks: 0 } ]
> >
> > <snip>
> > --
> > Ben.
>
> Maybe you mean it did create a regular graph with 4 nodes?
> But the program looks for regular graphs with x nodes in this case 5.
Maybe i have been unclear it look for regular graphs using the specified number of nodes.
Example chain.
0,1
1,2
2,3
3,4
4,0
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-03-02 12:41 +0000 |
| Message-ID | <87oaaxhx18.fsf@bsb.me.uk> |
| In reply to | #29764 |
jonas.thornvall@gmail.com writes:
> Den onsdag 2 mars 2016 kl. 11:59:36 UTC+1 skrev jonas.t...@gmail.com:
>> Den onsdag 2 mars 2016 kl. 11:44:05 UTC+1 skrev Ben Bacarisse:
>> > jonas.thornvall@gmail.com writes:
>> >
>> > <snip>
>> > Why did you post all those old lines? It's better to cut your messages
>> > down.
>> >
>> > > Phewww http://jt.node365.se/mydebug3.html
>> > >
>> > > Last minute rescue!!! At least i have not found any incorrect
>> > > reports. I think it breaks and decide correct for any generated
>> > > network.
>> >
>> > Not as far as I can see. One sample output:
>> >
>> > $ nodejs mydebug3.js
>> > Hurray **failed** generate regular graph
>> >
>> > [ { nodelinks: [ 4, 2 ], nroflinks: 0 },
>> > { nodelinks: [ 2, 4 ], nroflinks: 0 },
>> > { nodelinks: [ 0, 1 ], nroflinks: 0 },
>> > { nodelinks: [], nroflinks: 0 },
>> > { nodelinks: [ 0, 1 ], nroflinks: 0 } ]
>> >
>> > <snip>
>> > --
>> > Ben.
>>
>> Maybe you mean it did create a regular graph with 4 nodes?
>> But the program looks for regular graphs with x nodes in this case 5.
>
> Maybe i have been unclear it look for regular graphs using the
> specified number of nodes.
>
> Example chain.
> 0,1
> 1,2
> 2,3
> 3,4
> 4,0
That's called a cycle (of length 5). You want to generate regular
graphs of n nodes and degree d with no cycles of length 1? That can't
be it because the program does not do that. We are probably just
talking about different things. I'm glad it's doing whatever it is you
want, but you should still get rid of all those globals.
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2016-03-02 01:42 -0800 |
| Message-ID | <ffb4af7a-98b4-4552-b607-39d47d3be797@googlegroups.com> |
| In reply to | #29743 |
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?
>
> >> 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?
>
> > 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;
>
> But this can be simplified too, especially if you consider the next line:
>
> > if (aLink == nodes)aLink -- ;
>
> 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.
>
> > 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.
>
> > }
> > }
> > i ++ ;
> > }
> > myboolean = true;
> > return myboolean;
> > }
>
> --
> Ben.
http://jt.node365.se/mydebug3.html
I think this is quite good and i did a speed improvement.
More suggestions.
<HTML><BODY onLoad=init();>
<form name="network" onsubmit="init(); return false;" onSubmit>
Links:<input name="linkval" value="3" size="7" type="text"><br>
Multiple:<input name="lmult" value="3" size="3" type="text"><br>
Nodes: <input name="nodeval" value="" size="5" type="text" disabled><br>
<input type=submit name="network" value="NEW NETWORK"><br>
<textarea name="output" rows="100" cols="60"></textarea>
</form>
</BODY></HTML>
<script type="text/javascript">
function init()
{
links = document.network.linkval.value * 1;
multiple = document.network.lmult.value * 1;
nodes = (links * multiple) + 1;
document.network.nodeval.value = nodes;
arr = new Array();
myboolean = false;
// while(myboolean == false)
// {
createarr();
myboolean = createLinks();
// }
for (var z = 0; z < nodes; z ++ )
{
document.network.output.value += z + "'st NODE Links-> "+arr[z].nodelinks+"\n";
}
}
function createarr()
{
for(k = 0; k < nodes; k ++ )
{
arr[k] =
{
nodelinks : [], nroflinks : 0
}
;
}
}
function createLinks()
{
document.network.output.value = "";
var i = 0;
var j = 0;
var newnode = false;
// document.network.output.value += "[***START NODE***->0 \n";
while(i < nodes - 1)
{
// if(i < nodes - 1) document.network.output.value += "LINKS TO NODE -> " + arr[i].nodelinks + "\n\n";
j = arr[i].nodelinks.length;
temparr = new Array();
while(j < links)
{
dublett = false;
// Only have to generate random values that is bigger than "i" otherwise node full / exhausted
aLink = Math.floor(Math.random() * (nodes - 1 - i)) + i + 1;
if (temparr[0] == null)
{
temparr[0] = aLink;
}
for(k = 0; k < arr[i].nodelinks.length; k ++ )
{
if(aLink == arr[i].nodelinks[k])
{
dublett = true;
}
}
// document.network.output.value += i + "]" + " Linked-->" + aLink + " " + dublett + "\n";
if(dublett == false && arr[aLink].nodelinks.length < links)
{
// document.network.output.value += "[ADDED LINK] " + aLink + "\n\n";
arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
j ++ ;
newnode = true;
}
if (newnode == false)
{
inmylist = false;
for(var m = 0; m < temparr.length; m ++ )
{
if(temparr[m] == aLink)
{
inmylist = true;
// document.network.output.value += inmylist + "Nothing added to list [" + temparr + "\n";
}
}
if (inmylist == false)
{
temparr[temparr.length] = aLink;
// document.network.output.value += "Added to mylist" + temparr + "\n";
}
scope = (nodes - 1) - i;
// document.network.output.value += "Break if TRUE " + temparr.length + ">=" + scope + "\n";
if (temparr.length == scope)
{
document.network.output.value += "Hurray **failed** generate regular graph \n";
myboolean = false;
return myboolean;
}
}
newnode = false;
}
// document.network.output.value += "***FINISHED NODE*** " + i + " Links =" + arr[i].nodelinks + "\n\n";
i ++ ;
// document.network.output.value += "[***START NODE***-> " + i + " ";
}
if(arr[i].nodelinks.length < links)
{
document.network.output.value += "Hurray **failed** generate regular graph \n";
myboolean = false;
return myboolean;
}
else
{
document.network.output.value += "Hurray **succeded** to generate network!!!\n";
myboolean = true;
return myboolean;
}
}
</script>
[toc] | [prev] | [next] | [standalone]
| From | John Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2016-03-01 10:47 +0000 |
| Message-ID | <2psadblsa46tfkrqmafhnlm1bta41ghfer@4ax.com> |
| In reply to | #29739 |
On Mon, 29 Feb 2016 21:31:25 -0800 (PST), jonas.thornvall@gmail.com
wrote:
>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.
>
>http://jt.node365.se/mydebug1.html
function init()
{
links = document.network.linkval.value * 1;
multiple = document.network.lmult.value * 1;
nodes = (links * multiple) + 1;
document.network.nodeval.value = nodes;
arr = new Array();
Where are the var declarations for these global variables?
function createLinks()
{
document.network.output.value = "";
i = 0;
j = 0;
abort = 0;
Where are the var declarations for these local variables?
John
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web