-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mutualize code for onConstraint usage rules (#990)
- Loading branch information
Showing
4 changed files
with
72 additions
and
122 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
...c-impl/src/main/java/com/powsybl/openrao/data/cracimpl/AbstractOnConstraintUsageRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package com.powsybl.openrao.data.cracimpl; | ||
|
||
import com.powsybl.openrao.data.cracapi.Instant; | ||
import com.powsybl.openrao.data.cracapi.State; | ||
import com.powsybl.openrao.data.cracapi.cnec.Cnec; | ||
import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; | ||
|
||
/** | ||
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>} | ||
*/ | ||
public abstract class AbstractOnConstraintUsageRule<T extends Cnec<?>> extends AbstractUsageRule { | ||
protected Instant instant; | ||
protected T cnec; | ||
|
||
protected AbstractOnConstraintUsageRule(UsageMethod usageMethod, Instant instant, T cnec) { | ||
super(usageMethod); | ||
this.instant = instant; | ||
this.cnec = cnec; | ||
} | ||
|
||
@Override | ||
public UsageMethod getUsageMethod(State state) { | ||
if (state.isPreventive()) { | ||
return state.getInstant().equals(instant) ? usageMethod : UsageMethod.UNDEFINED; | ||
} else { | ||
return state.getInstant().equals(instant) && state.equals(cnec.getState()) ? usageMethod : UsageMethod.UNDEFINED; | ||
} | ||
} | ||
|
||
@Override | ||
public Instant getInstant() { | ||
return instant; | ||
} | ||
|
||
public T getCnec() { | ||
return cnec; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
AbstractOnConstraintUsageRule<?> rule = (AbstractOnConstraintUsageRule<?>) o; | ||
return super.equals(o) && rule.getInstant().equals(instant) && rule.getCnec().equals(cnec); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return cnec.hashCode() * 19 + instant.hashCode() * 47; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters