From 98f692a6d8f3f7afb4a672e8687fd712f52a23ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sun, 24 May 2020 17:48:11 +0200 Subject: [PATCH] Add method comparing survival dt examples attributes This will be used to check for duplicates when generating decision tree's examples. --- .../SurvivalDTExample.py | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/AI/DecisionTrees/projectSpecificClasses/SurvivalDTExample.py b/src/AI/DecisionTrees/projectSpecificClasses/SurvivalDTExample.py index e7be748..7888aea 100644 --- a/src/AI/DecisionTrees/projectSpecificClasses/SurvivalDTExample.py +++ b/src/AI/DecisionTrees/projectSpecificClasses/SurvivalDTExample.py @@ -35,4 +35,28 @@ class SurvivalDTExample(DecisionTreeExample): Attribute(SurvivalAttributesDefinitions.waterDistanceAttrDef, distFromWater), Attribute(SurvivalAttributesDefinitions.restDistanceAttrDef, distFromRestPlace)] - super().__init__(classification, attributes) \ No newline at end of file + super().__init__(classification, attributes) + + def compareAttributes(self, anotherExample) -> bool: + """ + Compares attributes of this example with another example's attributes. + + :param anotherExample: + :return: True if attrs are equal, False otherwise + """ + attrsAreEqual = True + + if self.hungerVal != anotherExample.hungerVal: + attrsAreEqual = False + elif self.thirstVal != anotherExample.thirstVal: + attrsAreEqual = False + elif self.staminaVal != anotherExample.staminaVal: + attrsAreEqual = False + elif self.distFromFood != anotherExample.distFromFood: + attrsAreEqual = False + elif self.distFromWater != anotherExample.distFromWater: + attrsAreEqual = False + elif self.distFromRestPlace != anotherExample.distFromRestPlace: + attrsAreEqual = False + + return attrsAreEqual