-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariable.py
More file actions
28 lines (22 loc) · 874 Bytes
/
Copy pathvariable.py
File metadata and controls
28 lines (22 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Variable container used during expression evaluation.
# Represents a named feature value in the GP individual evaluation.
from __future__ import annotations
class Variable:
def __init__(self, name: str):
self.name = name
self.initialized = False
self.value = None
def setValue(self, value: float):
self.value = value
self.initialized = True
def __str__(self) -> str:
if not self.initialized:
return self.name
else:
return f"{self.name}({self.value:.2f})"
@staticmethod
def setVariableValues(variableList: list, values: list) -> None:
if len(variableList) != len(values):
raise ValueError("Length of variable list and values list must be the same")
for i in range(len(variableList)):
variableList[i].setValue(values[i])