Run the simulation
(self)
| 134 | self.period = period |
| 135 | |
| 136 | def run(self): |
| 137 | """Run the simulation""" |
| 138 | |
| 139 | start = time.time() |
| 140 | awaitingInjectors = [] |
| 141 | awaitingInjectorsCounterWrap = Counter() |
| 142 | self.reset() |
| 143 | |
| 144 | push = heapq.heappush |
| 145 | pop = heapq.heappop |
| 146 | |
| 147 | state = self.state |
| 148 | stability_precision = self.stability_precision |
| 149 | period = self.period |
| 150 | |
| 151 | activation = None |
| 152 | iterations = 0 |
| 153 | |
| 154 | capCapacity = self.capacitorCapacity |
| 155 | tau = self.capacitorRecharge / 5.0 |
| 156 | |
| 157 | cap_wrap = self.startingCapacity # cap value at last period |
| 158 | cap_lowest = self.startingCapacity # lowest cap value encountered |
| 159 | cap_lowest_pre = self.startingCapacity # lowest cap value before activations |
| 160 | cap = self.startingCapacity # current cap value |
| 161 | t_wrap = self.period # point in time of next period |
| 162 | t_last = 0 |
| 163 | t_max = self.t_max |
| 164 | |
| 165 | while 1: |
| 166 | # Nothing to pop - might happen when no mods are activated, or when |
| 167 | # only cap injectors are active (and are postponed by code below) |
| 168 | try: |
| 169 | activation = pop(state) |
| 170 | except IndexError: |
| 171 | break |
| 172 | t_now, duration, capNeed, shot, clipSize, reloadTime, isInjector = activation |
| 173 | |
| 174 | # Max time reached, stop simulation - we're stable |
| 175 | if t_now >= t_max: |
| 176 | break |
| 177 | |
| 178 | # Regenerate cap from last time point |
| 179 | if t_now > t_last: |
| 180 | cap = ((1.0 + (sqrt(cap / capCapacity) - 1.0) * exp((t_last - t_now) / tau)) ** 2) * capCapacity |
| 181 | |
| 182 | if t_now != t_last: |
| 183 | if cap < cap_lowest_pre: |
| 184 | cap_lowest_pre = cap |
| 185 | if t_now == t_wrap: |
| 186 | # history is repeating itself, so if we have more cap now than last |
| 187 | # time this happened, it is a stable setup. |
| 188 | awaitingInjectorsCounterNow = Counter(awaitingInjectors) |
| 189 | if self.optimize_repeats and cap >= cap_wrap and awaitingInjectorsCounterNow == awaitingInjectorsCounterWrap: |
| 190 | self.result_optimized_repeats = True |
| 191 | break |
| 192 | cap_wrap = round(cap, stability_precision) |
| 193 | awaitingInjectorsCounterWrap = awaitingInjectorsCounterNow |
no test coverage detected