| Conditions | 8 |
| Paths | 34 |
| Total Lines | 33 |
| Code Lines | 23 |
| Lines | 6 |
| Ratio | 18.18 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 53 | public function run() |
||
| 54 | { |
||
| 55 | $i=0; |
||
|
|
|||
| 56 | $vec = []; |
||
| 57 | for ($i=0 ; $i<count($this->domain); $i++) { |
||
| 58 | $vec[]=rand($this->domain[$i][0], $this->domain[$i][1]); |
||
| 59 | } |
||
| 60 | while ($this->temperature > 0.1) { |
||
| 61 | $idx = rand(0, count($this->domain) - 1); |
||
| 62 | $dir = rand(-$this->step, $this->step); |
||
| 63 | $newVec = []; |
||
| 64 | for ($i=0; $i<count($vec); $i++) { |
||
| 65 | $newVec[]=($vec[$i]); |
||
| 66 | } |
||
| 67 | $newVec[$idx]+=$dir; |
||
| 68 | View Code Duplication | if ($newVec[$idx] < $this->domain[$idx][0]) { |
|
| 69 | $newVec[$idx] = $this->domain[$idx][0]; |
||
| 70 | } |
||
| 71 | View Code Duplication | if ($newVec[$idx] > $this->domain[$idx][1]) { |
|
| 72 | $newVec[$idx] = $this->domain[$idx][1]; |
||
| 73 | } |
||
| 74 | |||
| 75 | $ea = $this->cost->calc($vec); |
||
| 76 | $eb = $this->cost->calc($newVec); |
||
| 77 | $p = exp(-1*($eb-$ea)/$this->temperature); |
||
| 78 | if ($eb < $ea || (rand(0, 1000)/1000) < $p) { |
||
| 79 | $vec = $newVec; |
||
| 80 | } |
||
| 81 | |||
| 82 | $this->temperature *= $this->cool; |
||
| 83 | } |
||
| 84 | return $vec; |
||
| 85 | } |
||
| 86 | } |
||
| 87 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.