Hosted by
EDF
aqora template edf-pmrq
cd edf-pmrq
aqora install
src/submission/__init__.py
with your solution. You can
test your solution by runningaqora test
aqora upload
class Problem:
id: int
cost: np.ndarray
frequency: np.ndarray
tolerance: np.ndarray
offset: np.ndarray
T: int
credit: dict
epsilon: np.ndarray
def __init__(self, cost, frequency, tolerance, offset, credit, T):
self.id = id
self.cost = np.array(cost)
self.frequency = np.array(frequency)
self.tolerance = np.array(tolerance)
self.offset = np.array(offset)
self.T = T
self.credit = credit
self.epsilon = self.calc_epsilon(self.cost, credit)
def assert_valid(self, df: pd.DataFrame):
# Iterate over each row in the DataFrame
for row in df.index:
# Get the column indices where the row equals 1
ones_indices = df.loc[row][df.loc[row] == 1].index.tolist()
# this asserts whether the time between first maintenance and the previous one verifies the frequency and tolerance constraint
assert (
ones_indices[0] - self.offset[row] - 1
<= self.frequency[row] + self.tolerance[row]
)
# this asserts whether the time between consecutive maintenance verifies the frequency and tolerance constraint
diffs = np.diff(ones_indices)
assert np.all(np.abs(diffs - self.frequency[row]) <= self.tolerance[row])
# this asserts whether the last maintenance and the time horizon do not violate the frequency and tolerance constraint
assert (
self.T - ones_indices[-1] <= self.frequency[row] + self.tolerance[row]
)
def calc_cost(self, input: np.ndarray) -> float:
return np.trace(self.epsilon @ input @ input.T)
@classmethod
def calc_epsilon(cls, cost: np.ndarray, credit: dict) -> np.ndarray:
# Define the epsilon matrix
epsilon = np.zeros((len(cost), len(cost)))
# Populate the epsilon matrix with cost values. The value of the coefficient epsilon[i,j] is the cost of j which is free is the maintenance of i is done at the same time as j
for _, key in enumerate(credit):
for j in credit[key]:
epsilon[int(key) - 1, j - 1] = cost[j - 1]
return epsilon