A Candidate measures if a memory layout is suitable for a build configuration. If a build configuration shares an attribute with a Candidate, the Candidate gets a higher score. The scoring system is chosen such that the best Candidate is unique (i.e. 2**Importance).
| 43 | import re |
| 44 | |
| 45 | class Candidate(object): |
| 46 | """A Candidate measures if a memory layout is suitable |
| 47 | for a build configuration. If a build configuration |
| 48 | shares an attribute with a Candidate, the Candidate |
| 49 | gets a higher score. |
| 50 | The scoring system is chosen such that the best |
| 51 | Candidate is unique (i.e. 2**Importance). |
| 52 | """ |
| 53 | |
| 54 | IMPORTANCE = {'precision': 1, 'equations': 2, 'order': 3, 'pe': 4, 'multipleSimulations': 5} |
| 55 | |
| 56 | def __init__(self, atts): |
| 57 | self.atts = atts |
| 58 | |
| 59 | def score(self, reqs): |
| 60 | sc = 0 |
| 61 | for key,val in reqs.items(): |
| 62 | if key in self.atts: |
| 63 | if val == self.atts[key]: |
| 64 | sc += 2**self.IMPORTANCE[key] |
| 65 | else: # requirement not satisifed |
| 66 | return 0 |
| 67 | return sc |
| 68 | |
| 69 | def __repr__(self): |
| 70 | return repr(self.atts) |
| 71 | |
| 72 | def findCandidates(search_path): |
| 73 | """Determine Candidate attributes from file name.""" |