Skip to content

Commit

Permalink
Prepared inner class functions NArgMax, NArgMin, NMinValue, NMaxValue
Browse files Browse the repository at this point in the history
  • Loading branch information
axkr committed Jul 13, 2024
1 parent c54f0f4 commit 852328d
Showing 1 changed file with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
import org.matheclipse.core.visit.VisitorExpr;
import com.google.common.base.Suppliers;

/**
* The MinMaxFunctions class is a part of the symbolic math library and is used for mathematical
* optimization. It contains several nested classes, each representing a different mathematical
* function or operation. The class contains a static initializer block that sets evaluators for
* various mathematical functions.
*/
public class MinMaxFunctions {
private static final Logger LOGGER = LogManager.getLogger();

Expand All @@ -65,6 +71,9 @@ public class MinMaxFunctions {
*/
private static class Initializer {

/**
* The init method sets the evaluators for various mathematical functions.
*/
private static void init() {
S.ArgMax.setEvaluator(new ArgMax());
S.ArgMin.setEvaluator(new ArgMin());
Expand All @@ -75,6 +84,11 @@ private static void init() {
S.Minimize.setEvaluator(new Minimize());
S.NMaximize.setEvaluator(new NMaximize());
S.NMinimize.setEvaluator(new NMinimize());

// S.NArgMax.setEvaluator(new NArgMax());
// S.NArgMin.setEvaluator(new NArgMin());
// S.NMaxValue.setEvaluator(new NMaxValue());
// S.NMinValue.setEvaluator(new NMinValue());
}
}

Expand Down Expand Up @@ -131,6 +145,48 @@ public int[] expectedArgSize(IAST ast) {
}
}

/**
* The NArgMax function is used to find the values of the variables that maximize the given
* function.
*/
private static class NArgMax extends AbstractFunctionEvaluator {

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
IExpr maximize = engine.evaluate(F.NMaximize(ast.arg1(), ast.arg2()));
if (maximize.isList2() && maximize.second().isListOfRules()) {
IAST listOfRules = (IAST) maximize.second();
return listOfRules.map(x -> x.second());
}
return F.NIL;
}

@Override
public int[] expectedArgSize(IAST ast) {
return ARGS_2_2;
}
}

/**
* The NMaxValue function is used to find the maximum value for the given function.
*/
private static class NMaxValue extends AbstractFunctionEvaluator {

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
IExpr maximize = engine.evaluate(F.NMaximize(ast.arg1(), ast.arg2()));
if (maximize.isList2() && maximize.second().isListOfRules()) {
return maximize.first();
}
return F.NIL;
}

@Override
public int[] expectedArgSize(IAST ast) {
return ARGS_2_2;
}
}

/**
*
*
Expand Down Expand Up @@ -184,6 +240,48 @@ public int[] expectedArgSize(IAST ast) {
}
}

/**
* The NArgMin function is used to find the values of the variables that minimize the given
* function.
*/
private static class NArgMin extends AbstractFunctionEvaluator {

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
IExpr minimize = engine.evaluate(F.NMinimize(ast.arg1(), ast.arg2()));
if (minimize.isList2() && minimize.second().isListOfRules()) {
IAST listOfRules = (IAST) minimize.second();
return listOfRules.map(x -> x.second());
}
return F.NIL;
}

@Override
public int[] expectedArgSize(IAST ast) {
return ARGS_2_2;
}
}

/**
* The NMinValue function is used to find the minimum value for the given function.
*/
private static class NMinValue extends AbstractFunctionEvaluator {

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
IExpr minimize = engine.evaluate(F.NMinimize(ast.arg1(), ast.arg2()));
if (minimize.isList2() && minimize.second().isListOfRules()) {
return minimize.first();
}
return F.NIL;
}

@Override
public int[] expectedArgSize(IAST ast) {
return ARGS_2_2;
}
}

private static final class FunctionRange extends AbstractFunctionEvaluator {
private static Supplier<Matcher> LAZY_MATCHER;

Expand Down

0 comments on commit 852328d

Please sign in to comment.