but when removing enemy constraints
This commit is contained in:
parent
4e8c8416b6
commit
c15345867d
app
@ -3,21 +3,19 @@ from typing import Tuple
|
||||
from models.item import Item
|
||||
|
||||
def sanctify(solved_items: [Item]) -> Tuple[list]:
|
||||
sacred_ids = []
|
||||
enemy_ids = []
|
||||
|
||||
# get all enemies
|
||||
for item in solved_items:
|
||||
# if it has enemies, check if it exists as part of the solved items
|
||||
for enemy_id in item.enemies:
|
||||
# if it does, it's a true enemy
|
||||
if enemy_id in (item.id for item in solved_items):
|
||||
enemy_ids.append(enemy_id)
|
||||
# remove enemy from solved items,
|
||||
# lest it has this sacred item added to enemies
|
||||
solved_items = [i for i in solved_items if i.id != enemy_id]
|
||||
# if the item is already an an enemy
|
||||
# then it's enemy is sacred
|
||||
if item.id not in enemy_ids:
|
||||
# if it has enemies, check if it exists as part of the solved items
|
||||
for enemy_id in item.enemies:
|
||||
# if it does, it's a true enemy
|
||||
if enemy_id in (i.id for i in solved_items):
|
||||
enemy_ids.append(enemy_id)
|
||||
|
||||
# the item is cleansed, now it's sacred
|
||||
sacred_ids.append(item.id)
|
||||
sacred_ids = [i.id for i in solved_items if i.id not in enemy_ids]
|
||||
|
||||
return sacred_ids, enemy_ids
|
@ -1,4 +1,4 @@
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, validator
|
||||
from typing import List, Optional
|
||||
|
||||
from models.attribute import Attribute
|
||||
@ -16,6 +16,13 @@ class Item(BaseModel):
|
||||
b_param: float = 0.00
|
||||
response: Optional[int] = None
|
||||
|
||||
@validator("enemies", pre=True)
|
||||
def set_enemies(cls, v) -> List[id]:
|
||||
if v == "":
|
||||
return []
|
||||
enemies = list(filter(None, [int(enemy) for enemy in v.split(",")]))
|
||||
return enemies
|
||||
|
||||
def iif(self, irt_model, theta):
|
||||
return ItemInformationFunction(irt_model).calculate(b_param=self.b_param, theta=theta)
|
||||
|
||||
|
@ -8,7 +8,6 @@ from pulp import LpProblem, LpVariable, LpStatus, lpSum
|
||||
import logging
|
||||
|
||||
from helpers.problem_helper import *
|
||||
|
||||
from helpers import service_helper
|
||||
|
||||
from models.solution import Solution
|
||||
@ -67,8 +66,8 @@ class Problem(BaseModel):
|
||||
logging.info('enemies found, adding constraints...')
|
||||
|
||||
# remove old enemy/sacred constraints
|
||||
self.problem.constraints.pop('Exclude_enemy_items')
|
||||
self.problem.constraints.pop('Include_sacred_items')
|
||||
if 'Exclude_enemy_items' in self.problem.constraints.keys(): self.problem.constraints.pop('Exclude_enemy_items')
|
||||
if 'Include_sacred_items' in self.problem.constraints.keys(): self.problem.constraints.pop('Include_sacred_items')
|
||||
|
||||
# add constraint to not allow enemy items
|
||||
self.problem += lpSum([
|
||||
|
Loading…
x
Reference in New Issue
Block a user