• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PolyMathOrg / PolyMath / 4224622076

pending completion
4224622076

push

github

GitHub
Merge pull request #305 from jecisc/depend-on-polymath-datastructures

9387 of 13597 relevant lines covered (69.04%)

2.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.89
/src/Math-Core-Process/PMIterativeProcess.class.st
1
"
2
A `PMIterativeProcess` class is an abstract base class for processes which follow an iterative pattern. 
3

4
Subclasses of `PMIterativeProcess` will redefine:
5
- `initializeIterations`
6
- `evaluateIteration`
7
- `finalizeIterations`
8

9
The instance variable `result` is used to store the most recent/best result, and is accessible through the result selector.
10

11
The maximumIterations: method allows control of the amount of work this method is allowed to do. Each evaluation of the iteration increments the instance variable `iterations`. When this number exceeds `maximumIterations,` the evaluate method will stop the process, and answer `result`.
12

13
"
14
Class {
15
        #name : #PMIterativeProcess,
16
        #superclass : #Object,
17
        #instVars : [
18
                'precision',
19
                'desiredPrecision',
20
                'maximumIterations',
21
                'result',
22
                'iterations'
23
        ],
24
        #category : #'Math-Core-Process'
25
}
26

27
{ #category : #default }
28
PMIterativeProcess class >> defaultMaximumIterations [
3✔
29
        "Private - Answers the default maximum number of iterations for newly created instances."
3✔
30
        ^50
3✔
31
]
3✔
32

33
{ #category : #default }
34
PMIterativeProcess class >> defaultPrecision [
3✔
35
        "Private - Answers the default precision for newly created instances."
3✔
36
        ^PMFloatingPointMachine new defaultNumericalPrecision
3✔
37
]
3✔
38

39
{ #category : #initialization }
40
PMIterativeProcess >> desiredPrecision: aNumber [
3✔
41
        "Defines the desired precision for the result."
3✔
42
        aNumber > 0
3✔
43
                ifFalse: [ ^self error: 'Illegal precision: ', aNumber printString].
3✔
44
        desiredPrecision := aNumber.
3✔
45
]
3✔
46

47
{ #category : #operation }
48
PMIterativeProcess >> evaluate [
3✔
49
        "Perform the iteration until either the desired precision is attained or the number of iterations exceeds the maximum."
3✔
50

3✔
51
        iterations := 0.
3✔
52
        self initializeIterations.
3✔
53
        
3✔
54
        [iterations := iterations + 1.
3✔
55
        precision := self evaluateIteration.
3✔
56
        self hasConverged or: [iterations >= maximumIterations]] 
3✔
57
                        whileFalse: [].
3✔
58
        self finalizeIterations.
3✔
59
        ^self result
3✔
60
]
3✔
61

62
{ #category : #operation }
63
PMIterativeProcess >> evaluateIteration [
64
        "Dummy method (must be implemented by subclass)."
65
        ^self subclassResponsibility
66
]
67

68
{ #category : #operation }
69
PMIterativeProcess >> finalizeIterations [
3✔
70
        "Perform cleanup operation if needed (must be implemented by subclass)."
3✔
71
]
3✔
72

73
{ #category : #information }
74
PMIterativeProcess >> hasConverged [
3✔
75

3✔
76
        ^precision <= desiredPrecision
3✔
77
]
3✔
78

79
{ #category : #initialization }
80
PMIterativeProcess >> initialize [
3✔
81

3✔
82
        desiredPrecision := self class defaultPrecision.
3✔
83
        maximumIterations := self class defaultMaximumIterations.
3✔
84
        ^self
3✔
85
]
3✔
86

87
{ #category : #operation }
88
PMIterativeProcess >> initializeIterations [
×
89
        "Initialize the iterations (must be implemented by subclass when needed)."
×
90
]
×
91

92
{ #category : #information }
93
PMIterativeProcess >> iterations [
3✔
94
        "Answers the number of iterations performed."
3✔
95
        ^iterations
3✔
96
]
3✔
97

98
{ #category : #private }
99
PMIterativeProcess >> limitedSmallValue: aNumber [
3✔
100
        "Private - prevent aNumber from being smaller in absolute value than a small number."
3✔
101
        ^aNumber abs < PMFloatingPointMachine new smallNumber
3✔
102
                        ifTrue: [ PMFloatingPointMachine new smallNumber]
3✔
103
                        ifFalse:[ aNumber]
3✔
104
]
3✔
105

106
{ #category : #initialization }
107
PMIterativeProcess >> maximumIterations: anInteger [
3✔
108
        "Defines the maximum number of iterations."
3✔
109
        ( anInteger isInteger and: [ anInteger > 1])
3✔
110
                ifFalse: [ ^self error: 'Invalid maximum number of iteration: ', anInteger printString].
3✔
111
        maximumIterations := anInteger.
3✔
112
]
3✔
113

114
{ #category : #information }
115
PMIterativeProcess >> precision [
3✔
116
        "Answer the attained precision for the result."
3✔
117
        ^precision
3✔
118
]
3✔
119

120
{ #category : #information }
121
PMIterativeProcess >> precisionOf: aNumber1 relativeTo: aNumber2 [
3✔
122
        
3✔
123
        ^aNumber2 > PMFloatingPointMachine new defaultNumericalPrecision
3✔
124
                ifTrue: [ aNumber1 / aNumber2]
3✔
125
                ifFalse:[ aNumber1]
3✔
126
]
3✔
127

128
{ #category : #information }
129
PMIterativeProcess >> result [
3✔
130
        "Answer the result of the iterations (if any)"
3✔
131
        ^result
3✔
132
]
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc