<div dir="ltr">err, set also is unordered. I can see you are using set for a reason, but has no concept of order.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Apr 26, 2014 at 3:20 PM, C Smith <span dir="ltr"><<a href="mailto:illusiontechniques@gmail.com" target="_blank">illusiontechniques@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Just glancing at your work, I see you have curly braces around what looks like it should be a list. If you are concerned with the order of your output, dictionaries do not have a concept of order.<br>
</div><div class="gmail_extra">
<br><br><div class="gmail_quote"><div><div class="h5">On Sat, Apr 26, 2014 at 3:16 PM, Suhana Vidyarthi <span dir="ltr"><<a href="mailto:suhanavidyarthi@gmail.com" target="_blank">suhanavidyarthi@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
<div dir="ltr">Hi Danny,<div><br></div><div>Let me give you a high level brief of what I am doing:</div><div>I am working on doing "disaster aware routing" considering the 24-node US network where I will be setting up connection between two any two nodes (I will select the source and destination nodes randomly). Also I have some links whose "probability of failure" is mentioned in the attached file. Other links, which are not mentioned in the file - we suppose their "probability of failure" is zero. So between the source-destination nodes, there will be multiple paths and I will select the one which has "least probability of failure".</div>


<div><br></div><div>Now to setup the connection between two nodes, I have to select a path whose "probability of failure" is least. To do that first I will calculate the risk of each path from the attached file and then select the path with least risk value. Did you get this part? I know it can be a bit confusing.</div>


<div><br></div><div>Now I break the problem into parts:</div><div><br></div><div>1. I have to topology of the 24-node map </div><div>2. I have the link values of each link - where risk values are the "probability of failure"</div>


<div>3. I calculate the total "probability of failure" of each path (a path may have multiple links): Suppose my source node is "a" and destination node is "b". I can setup a path between a to b via c or via d (a-c-b or a-d-c): Here I will check the risk values of a-c and c-b; also risk values of a-d and d-c. If the total risk valure of a-c-b is lower that risk value of a-d-c, then I select the path a-c-d to setup the connection. (again risk value = probability of failure)</div>


<div><br></div><div>Now, I will first calculate the "total probability of failure" of each link (using the file.txt) and since some links are repeated their values will be added. <span style="letter-spacing:0px;font-family:'Trebuchet MS'">The probabilities get added if a link is mentioned twice or thrice. For example:</span><span style="letter-spacing:0px;font-family:'Trebuchet MS'">  </span><span style="letter-spacing:0px;font-family:'Trebuchet MS'">link 3—5 is repeated 3 times: in line one, it has a probability of failure as 0.03, in line two it is 0.11 and in line three it is 0.04. So the probability of failure for link 3—5 is 0.03+0.11+0.04 = 0.18</span></div>


<div><span style="letter-spacing:0px;font-family:'Trebuchet MS'"><br></span></div><div><font face="Trebuchet MS"><span style="letter-spacing:0px">The </span>length<span style="letter-spacing:0px"> of each array will be same. You see the code I wrote: here is the output for it:</span></font></div>

<div>
<div><p style="margin:0px;font-size:12px;font-family:'Andale Mono';color:rgb(41,249,20);background-color:rgb(0,0,0)">Links -></p>
<p style="margin:0px;font-size:12px;font-family:'Andale Mono';color:rgb(41,249,20);background-color:rgb(0,0,0)">[('10', '13'), ('14', '18'), ('7', '8'), ('15', '20'), ('5', '8'), ('5', '4'), ('11', '9'), ('21', '22'), ('12', '13'), ('21', '20'), ('17', '13'), ('20', '21'), ('21', '16'), ('14', '10'), ('11', '12'), ('11', '19'), ('14', '13'), ('3', '5'), ('11', '6'), ('19', '20')]</p>



<p style="margin:0px;font-size:12px;font-family:'Andale Mono';color:rgb(41,249,20);background-color:rgb(0,0,0);min-height:14px"><br></p>
<p style="margin:0px;font-size:12px;font-family:'Andale Mono';color:rgb(41,249,20);background-color:rgb(0,0,0)">Probability -></p>
<p style="margin:0px;font-size:12px;font-family:'Andale Mono';color:rgb(41,249,20);background-color:rgb(0,0,0)">[0.04, 0.06, 0.04, 0.24, 0.08, 0.15, 0.08, 0.27, 0.04, 0.29, 0.08, 0.27, 0.27, 0.04, 0.08, 0.08, 0.08, 0.18000000000000002, 0.08, 0.24]</p>


</div>
<p style="margin:0px;font-family:'Trebuchet MS';min-height:12px"><br><span style="letter-spacing:0px"></span></p></div><p style="margin:0px;font-family:'Trebuchet MS';min-height:12px">It means that link [10,13] has a "probability of failure" as [0.04] and since the link [3-5] is repeated thrice with probability of 0.03, 0.11 and 0.04, its "probability of failure" is [0.18] (third last element in the Probability array). For some reason instead of 0.18 it is showing 0.180000000002, which I cannot figure to why.</p>


<p style="margin:0px;font-family:'Trebuchet MS';min-height:12px"><br></p><p style="margin:0px;font-family:'Trebuchet MS';min-height:12px">Please see the attached code. If you see the file.txt and my output: the output is not displayed in sequence and that is what I need help with. I want this to display :</p>


<p style="margin:0px;font-family:'Trebuchet MS';min-height:12px"><br></p><p style="margin:0px;font-family:'Trebuchet MS'"><span style="letter-spacing:0px">Links = { [3,5] [5,4] [5,8] [7,8] [14,10] [14,13] [17,13] [14,18] [10,13] [14,13] [17,13] [12,13] [11,6] [11,9] [11,12] [11,19] [19,20] [15,20] [21,20] [20,21] [21,16] [21,22] }</span></p>


<p style="margin:0px;font-family:'Trebuchet MS';min-height:12px"><span style="letter-spacing:0px"></span><br></p><p style="margin:0px;font-family:'Trebuchet MS';min-height:12px">

</p><p style="margin:0px;font-family:'Trebuchet MS'"><span style="letter-spacing:0px">Prob = {[0.18] [0.15] [0.08] [0.04] [0.04] [0.04] [0.08] [0.04] [0.08] [0.08] [0.08] [0.08] [0.24] [0.24] [0.34] [0.27] [0.27]}</span></p>


<p style="margin:0px;font-family:'Trebuchet MS'"><span style="letter-spacing:0px"><br></span></p><p style="margin:0px;font-family:'Trebuchet MS'">If you can figure why the output is not generated in same sequence as in the file.txt for me, it will be very helpful.</p>


<p style="margin:0px;font-family:'Trebuchet MS'"><br></p><p style="margin:0px;font-family:'Trebuchet MS'">let me know if I explained correctly, and if you have any questions or doubts?</p></div><div>
<div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Sat, Apr 26, 2014 at 11:41 AM, Danny Yoo <span dir="ltr"><<a href="mailto:dyoo@hashcollision.org" target="_blank">dyoo@hashcollision.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div>>>> I want to create two arrays using the above file (Links array and Prob<br>
>>> array) that should give following output:<br>
>>><br>
>>> *Links *= { [3,5] [5,4] [5,8] [7,8] [14,10] [14,13] [17,13] [14,18]<br>
>>> [10,13] [14,13] [17,13] [12,13] [11,6] [11,9][11,12] [11,19] [19,20]<br>
>>> [15,20] [21,20] [20,21] [21,16] [21,22] }<br>
>>><br>
>>> *Prob *= {[0.28] [0.15] [0.08] [0.04] [0.04] [0.04] [0.08] [0.04] [0.08]<br>
>>> [0.08] [0.08] [0.08] [0.24] [0.24] [0.34] [0.27] [0.27]}<br>
>><br>
>><br>
>> I don't understand how you develop this? The first list has 22 items the<br>
>> second 17. I would have expected them to be the same?<br>
><br>
><br>
> In the "Prob" array the elements are less because if you read the note<br>
> below: I said the links that are repeating for example [3,5] their<br>
> probabilities  get added and stored as a single value in the "Prob" array.<br>
<br>
<br>
</div>But what will you plan to do with these values afterwards?  I think<br>
Alan's point here is that if there's no direct relationship between<br>
the elements in Links and the elements in Probs, those values aren't<br>
going to be very useful to solve the rest of the problem.<br>
<br>
<br>
One way to look at this problem is to simplify or normalize the input;<br>
the original structure in the file is slightly weird to process, since<br>
a single line of the input represents several link/failure pairs.<br>
<br>
One concrete example is:<br>
<br>
    4,10,13,14,13,17,13,12,13,0.04<br>
<br>
where all these numbers are uninterpreted.<br>
<br>
You can imagine something that takes the line above, and breaks it<br>
down into a series of LinkFailure items.<br>
<br>
######<br>
class LinkFailure(object):<br>
    """Represents a link and the probability of failure."""<br>
    def __init__(self, start, end, failure):<br>
        self.start = start<br>
        self.end = end<br>
        self.failure = failure<br>
######<br>
<br>
which represent a link and failure structure.  If we have a structure<br>
like this, then it explicitly represents a relationship between a link<br>
and its failure, and the string line:<br>
<br>
    4,10,13,14,13,17,13,12,13,0.04<br>
<br>
can be distilled and represented as a collection of LinkFailure instances:<br>
<br>
    [LinkFailure(10, 13, 0.04), LinkFailure(14, 13, 0.04),<br>
LinkFailure(17, 13, 0.04), LinkFailure(12, 13, 0.04)]<br>
<br>
Then the relationship is explicit.<br>
<div><br>
<br>
>> Also why do you want these two lists? What do you plan on doing with them?<br>
>> I would have thought a mapping of link to probability would be much more<br>
>> useful? (mapping => dictionary)<br>
><br>
><br>
> I want these two lists because using the links and probs array, I will check<br>
> which link has the lowest probability. Here lowest probability means the<br>
> risk of failure for that link. So based on which link has least probability<br>
> of failure, I will use it to setup a connection (I have a source and<br>
> destination and the links mentioned above are the paths between them) I want<br>
> to select the path which has least failure probability.<br>
><br>
> Did it make sense?<br>
<br>
<br>
</div>Unfortunately, I'm still confused.  If you just have the Links and the<br>
Probs lists of unequal length, unless there's some additional<br>
information that you're represented, then I don't see the necessary<br>
connection between the two lists that lets you go any further in the<br>
problem.  There's no one-to-one-ness: given a link in Links, which<br>
Probs do you want to look at?  If you don't represent that linkage in<br>
some way, I don't understand yet where you go next.<br>
<div><br>
<br>
>>> So the first element in Links array is [3,5] and its probability of<br>
>>> failure is the first element in Prob array i.e. 0.28<br>
<br>
</div>But if the two lists are different lengths, what probability of<br>
failure is associates with the last element in the Prob array?<br>
<br>
<br>
The representation of data is important: if you choose an awkward<br>
representation, it makes solving this problem more difficult than it<br>
needs be.  That is, if you're already compressing multiple elements in<br>
Prob that correspond to the same link, you also need some way to<br>
figure out what link that a compressed probability refer to.<br>
Otherwise, you don't have enough information to solve the problem<br>
anymore.<br>
</blockquote></div><br></div>
</div></div><br></div></div><div class="">_______________________________________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org" target="_blank">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="https://mail.python.org/mailman/listinfo/tutor" target="_blank">https://mail.python.org/mailman/listinfo/tutor</a><br>
<br></div></blockquote></div><br></div>
</blockquote></div><br></div>