Skip to content

Commit

Permalink
Delete useless class for knitro stopping criteria
Browse files Browse the repository at this point in the history
Signed-off-by: jarchambault <[email protected]>
  • Loading branch information
jeanneArchambault committed Dec 11, 2024
1 parent 39ced36 commit 325c3fa
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 72 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<java.version>17</java.version>
<powsybl-core.version>6.6.0-RC1</powsybl-core.version>
<powsybl-open-loadflow.version>1.14.0-SNAPSHOT</powsybl-open-loadflow.version>
<knitro-interfaces.version>14.1.0</knitro-interfaces.version>
<knitro-interfaces.version>14.0.0</knitro-interfaces.version>
<bridj.version>0.7.0</bridj.version>
</properties>

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public class KnitroLoadFlowParameters extends AbstractExtension<LoadFlowParamete
private double lowerVoltageBound = KnitroSolverParameters.DEFAULT_LOWER_VOLTAGE_BOUND;
private double upperVoltageBound = KnitroSolverParameters.DEFAULT_UPPER_VOLTAGE_BOUND;
private int maxIterations = KnitroSolverParameters.DEFAULT_MAX_ITERATIONS;
private KnitroSolverStoppingCriteria stoppingCriteria = new KnitroSolverStoppingCriteria() {
};
private double convEps = KnitroSolverParameters.DEFAULT_STOPPING_CRITERIA;

public int getGradientComputationMode() {
return gradientComputationMode;
Expand Down Expand Up @@ -87,12 +86,15 @@ public KnitroLoadFlowParameters setMaxIterations(int maxIterations) {
return this;
}

public KnitroSolverStoppingCriteria getStoppingCriteria() {
return stoppingCriteria;
public double getConvEps() {
return convEps;
}

public KnitroLoadFlowParameters setStoppingCriteria(KnitroSolverStoppingCriteria stoppingCriteria) {
this.stoppingCriteria = Objects.requireNonNull(stoppingCriteria);
public KnitroLoadFlowParameters setConvEps(double convEps) {
if (convEps < 0) {
throw new IllegalArgumentException("Convergence stopping criteria must be greater than 0");
}
this.convEps = convEps;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,7 @@ private KnitroProblem(LfNetwork lfNetwork, EquationSystem<AcVariableType, AcEqua

private void setSolverParameters(KNSolver solver, KnitroSolverParameters knitroParameters) throws KNException {
solver.setParam(KNConstants.KN_PARAM_GRADOPT, knitroParameters.getGradientComputationMode());
DefaultKnitroSolverStoppingCriteria knitroSolverStoppingCriteria = (DefaultKnitroSolverStoppingCriteria) knitroParameters.getStoppingCriteria();
solver.setParam(KNConstants.KN_PARAM_FEASTOL, knitroSolverStoppingCriteria.convEpsPerEq);
solver.setParam(KNConstants.KN_PARAM_FEASTOL, knitroParameters.getConvEps());
solver.setParam(KNConstants.KN_PARAM_MAXIT, knitroParameters.getMaxIterations());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public String getName() {
public AcSolverParameters createParameters(LoadFlowParameters parameters) {
OpenLoadFlowParameters parametersExt = OpenLoadFlowParameters.get(parameters);
KnitroSolverParameters knitroSolverParameters = new KnitroSolverParameters()
.setStoppingCriteria(createKnitroStoppingCriteria(parametersExt))
.setStateVectorScalingMode(parametersExt.getStateVectorScalingMode())
.setLineSearchStateVectorScalingMaxIteration(parametersExt.getLineSearchStateVectorScalingMaxIteration())
.setLineSearchStateVectorScalingStepFold(parametersExt.getLineSearchStateVectorScalingStepFold())
Expand All @@ -50,7 +49,9 @@ public AcSolverParameters createParameters(LoadFlowParameters parameters) {
.setGradientUserRoutine(parameters.getExtension(KnitroLoadFlowParameters.class).getGradientUserRoutine())
.setLowerVoltageBound(parameters.getExtension(KnitroLoadFlowParameters.class).getLowerVoltageBound())
.setUpperVoltageBound(parameters.getExtension(KnitroLoadFlowParameters.class).getUpperVoltageBound())
.setMaxIterations(parameters.getExtension(KnitroLoadFlowParameters.class).getMaxIterations());
.setMaxIterations(parameters.getExtension(KnitroLoadFlowParameters.class).getMaxIterations())
.setConvEps(parameters.getExtension(KnitroLoadFlowParameters.class).getConvEps());

}
return knitroSolverParameters;
}
Expand All @@ -63,7 +64,4 @@ public AcSolver create(LfNetwork network, AcLoadFlowParameters parameters, Equat
j, targetVector, equationVector, parameters.isDetailedReport());
}

private static KnitroSolverStoppingCriteria createKnitroStoppingCriteria(OpenLoadFlowParameters parametersExt) {
return new DefaultKnitroSolverStoppingCriteria();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class KnitroSolverParameters implements AcSolverParameters {
public static final double DEFAULT_LOWER_VOLTAGE_BOUND = 0.5; // Lower bound for voltage magnitude
public static final double DEFAULT_UPPER_VOLTAGE_BOUND = 1.5; // Upper bound for voltage magnitude
public static final int DEFAULT_MAX_ITERATIONS = 200;
public static final double DEFAULT_STOPPING_CRITERIA = Math.pow(10,-6);
public static final StateVectorScalingMode DEFAULT_STATE_VECTOR_SCALING_MODE = StateVectorScalingMode.NONE;
public static final boolean ALWAYS_UPDATE_NETWORK_DEFAULT_VALUE = false;

Expand All @@ -44,12 +45,12 @@ public class KnitroSolverParameters implements AcSolverParameters {

private double upperVoltageBound = DEFAULT_UPPER_VOLTAGE_BOUND;

private KnitroSolverStoppingCriteria stoppingCriteria = new DefaultKnitroSolverStoppingCriteria();

private boolean alwaysUpdateNetwork = ALWAYS_UPDATE_NETWORK_DEFAULT_VALUE;

private int maxIterations = DEFAULT_MAX_ITERATIONS;

private double convEps = DEFAULT_STOPPING_CRITERIA;

public int getGradientComputationMode() {
return gradientComputationMode;
}
Expand Down Expand Up @@ -101,15 +102,6 @@ public KnitroSolverParameters setUpperVoltageBound(double upperVoltageBound) {
return this;
}

public KnitroSolverStoppingCriteria getStoppingCriteria() {
return stoppingCriteria;
}

public KnitroSolverParameters setStoppingCriteria(KnitroSolverStoppingCriteria stoppingCriteria) {
this.stoppingCriteria = Objects.requireNonNull(stoppingCriteria);
return this;
}

public StateVectorScalingMode getStateVectorScalingMode() {
return stateVectorScalingMode;
}
Expand Down Expand Up @@ -174,11 +166,20 @@ public KnitroSolverParameters setMaxIterations(int maxIterations) {
return this;
}

public double getConvEps() {
return convEps;
}

public KnitroSolverParameters setConvEps(double convEps) {
this.convEps = convEps;
return this;
}

@Override
public String toString() {
return "KnitroSolverParameters(" +
"gradientComputationMode=" + gradientComputationMode +
", stoppingCriteria=" + stoppingCriteria.getClass().getSimpleName() +
", stoppingCriteria=" + convEps +
", minRealisticVoltage=" + lowerVoltageBound +
", maxRealisticVoltage=" + upperVoltageBound +
", alwaysUpdateNetwork=" + alwaysUpdateNetwork +
Expand Down

This file was deleted.

0 comments on commit 325c3fa

Please sign in to comment.