/timm's /charming /python /tricks

model.py

Download model.py.
Read more on How to be Charming (in Python).


01: import sys
02: sys.dont_write_bytecode=True
03: from table import *
04: 
05: class Model(Charmed):
06:   "Information about decision,objective pairs."
07:   def __init__(i):
08:     i.t = Table()
09:     for x in i.has():
10:       i.t.has(x)
11:   def name(i): return i.__class__.__name__
12:   def valid(i,lst) : return True
13:   def empty(i):
14:     return [None] * len(i.t.columns)
15:   def decisions(i,repeats=The.model.repeats): 
16:     for _ in range(repeats):
17:       tmp = i.empty()
18:       for col in i.t.indep:
19:         tmp[col.pos] = col.any()
20:       if i.valid(tmp):
21:         return tmp
22:     return None
23:   def get(i,lst,x) : return lst[i.t.at(x)]
24:   def put(i,lst,x,y) : lst[i.t.at(x)] = y 
25:   def seen(i,lst):
26:     i.score(lst)
27:     i.t.seen(lst)
28:     return lst
29:   def any(i):
30:     new = i.decisions()
31:     if new:
32:       return i.seen(new)
33:  
34: 

This file is part of Timm's charming Python tricks.
© 2014, Tim Menzies: tim.menzies@gmail.com, http://menzies.us.

Timm's charming Python tricks are free software: you can redistribute it and/or modify it under the terms of the GNU Lesser Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Timm's charming Python tricks are distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU Lesser Public License along with Foobar. If not, see http://www.gnu.org/licenses.