Search in sources :

Example 1 with FloatConstant

use of org.tweetyproject.math.term.FloatConstant in project TweetyProject by TweetyProjectTeam.

the class ApacheCommonsCMAESOptimizerEx method createConstraintSatProb1.

/**
 * constructor
 * @return the problem
 */
public static ConstraintSatisfactionProblem createConstraintSatProb1() {
    FloatVariable m1 = new FloatVariable("Machine 1", -50, 100);
    FloatVariable m2 = new FloatVariable("Machine 2", -50, 100);
    // Target funcion = (m1+1)^2+m2^2
    Term opt = new Sum(new Power(new Sum(m1, new FloatConstant(-1)), new IntegerConstant(2)), new Power(m2, new IntegerConstant(2)));
    OptimizationProblem prob = new OptimizationProblem();
    ((OptimizationProblem) prob).setTargetFunction(opt);
    return prob;
}
Also used : FloatConstant(org.tweetyproject.math.term.FloatConstant) OptimizationProblem(org.tweetyproject.math.opt.problem.OptimizationProblem) Sum(org.tweetyproject.math.term.Sum) Term(org.tweetyproject.math.term.Term) FloatVariable(org.tweetyproject.math.term.FloatVariable) Power(org.tweetyproject.math.term.Power) IntegerConstant(org.tweetyproject.math.term.IntegerConstant)

Example 2 with FloatConstant

use of org.tweetyproject.math.term.FloatConstant in project TweetyProject by TweetyProjectTeam.

the class ApacheCommonsSimplexEx method createConstraintSatProb1.

/**
 * constructor
 * @return the problem
 */
public static ConstraintSatisfactionProblem createConstraintSatProb1() {
    // Define the constraints (all are equations)
    IntegerVariable m1 = new IntegerVariable("Maschine 1");
    IntegerVariable m2 = new IntegerVariable("Maschine 2");
    Inequation constr1 = new Inequation(m1, new IntegerConstant(10), 1);
    Inequation constr2 = new Inequation(m2, new IntegerConstant(12), 1);
    Inequation constr3 = new Inequation(m1, new IntegerConstant(0), 3);
    Inequation constr4 = new Inequation(m2, new IntegerConstant(0), 3);
    Inequation constr5 = new Inequation(m1.add(m2), new IntegerConstant(16), 0);
    Collection<Statement> constraints = new ArrayList<Statement>();
    constraints.add(constr1);
    constraints.add(constr2);
    constraints.add(constr3);
    constraints.add(constr4);
    constraints.add(constr5);
    OptimizationProblem prob = new OptimizationProblem(1);
    prob.addAll(constraints);
    // Define targetfunction
    Term opt = new Sum(new Sum(m1, new FloatConstant(1)), m2);
    prob.setTargetFunction(opt);
    return prob;
}
Also used : IntegerVariable(org.tweetyproject.math.term.IntegerVariable) Inequation(org.tweetyproject.math.equation.Inequation) Statement(org.tweetyproject.math.equation.Statement) FloatConstant(org.tweetyproject.math.term.FloatConstant) ArrayList(java.util.ArrayList) OptimizationProblem(org.tweetyproject.math.opt.problem.OptimizationProblem) Sum(org.tweetyproject.math.term.Sum) Term(org.tweetyproject.math.term.Term) IntegerConstant(org.tweetyproject.math.term.IntegerConstant)

Example 3 with FloatConstant

use of org.tweetyproject.math.term.FloatConstant in project TweetyProject by TweetyProjectTeam.

the class HessianGradientSolverEx method createConstraintSatProb1.

/**
 * constructor
 * @return problem
 */
public static ConstraintSatisfactionProblem createConstraintSatProb1() {
    FloatVariable m1 = new FloatVariable("Machine 1");
    FloatVariable m2 = new FloatVariable("Machine 2");
    // Target funcion = (m1+1)^2+m2^2
    Term opt = new Sum(new Power(new Sum(m1, new FloatConstant(1)), new IntegerConstant(2)), new Power(m2, new IntegerConstant(2)));
    OptimizationProblem prob = new OptimizationProblem();
    ((OptimizationProblem) prob).setTargetFunction(opt);
    return prob;
}
Also used : FloatConstant(org.tweetyproject.math.term.FloatConstant) OptimizationProblem(org.tweetyproject.math.opt.problem.OptimizationProblem) Sum(org.tweetyproject.math.term.Sum) Term(org.tweetyproject.math.term.Term) FloatVariable(org.tweetyproject.math.term.FloatVariable) Power(org.tweetyproject.math.term.Power) IntegerConstant(org.tweetyproject.math.term.IntegerConstant)

Example 4 with FloatConstant

use of org.tweetyproject.math.term.FloatConstant in project TweetyProject by TweetyProjectTeam.

the class KnapSack_solvedWithTabuSearch method main.

/**
 * main method
 * @param args arguments
 */
public static void main(String[] args) {
    // define the maximum weight
    FloatConstant maxl = new FloatConstant(15);
    // create a list of items defined by weight and value
    ArrayList<ElementOfCombinatoricsProb> elems = new ArrayList<ElementOfCombinatoricsProb>();
    for (int i = 0; i < 10; i++) {
        ElementOfCombinatoricsProb x = new ElementOfCombinatoricsProb(new ArrayList<Term>());
        x.components.add(new IntegerConstant((int) (Math.random() * 10) + 1));
        x.components.add(new IntegerConstant((int) (Math.random() * 10) + 1));
        elems.add(x);
    }
    KnapSack test = new KnapSack(elems, maxl);
    // solve the problem with a tabu size of 5, max 100000 iterations and max 2000 iterations without an improvement to the best solution
    TabuSearch ts = new TabuSearch(1000000, 50, 1000);
    ArrayList<ElementOfCombinatoricsProb> mySol = ts.solve(test);
    System.out.println("MySol: ");
    for (ElementOfCombinatoricsProb i : mySol) System.out.print(i.components + " ");
}
Also used : ElementOfCombinatoricsProb(org.tweetyproject.math.term.ElementOfCombinatoricsProb) FloatConstant(org.tweetyproject.math.term.FloatConstant) ArrayList(java.util.ArrayList) TabuSearch(org.tweetyproject.math.opt.solver.TabuSearch) Term(org.tweetyproject.math.term.Term) IntegerConstant(org.tweetyproject.math.term.IntegerConstant)

Example 5 with FloatConstant

use of org.tweetyproject.math.term.FloatConstant in project TweetyProject by TweetyProjectTeam.

the class LpSolverEx method createConstraintSatProb1.

/**
 * constructor
 * @return problem
 */
public static ConstraintSatisfactionProblem createConstraintSatProb1() {
    // Define the constraints (all are equations)
    FloatVariable m1 = new FloatVariable("Maschine1");
    FloatVariable m2 = new FloatVariable("Maschine2");
    Inequation constr1 = new Inequation(m1, m2, 1);
    Inequation constr2 = new Inequation(m2, new FloatConstant(11), 1);
    Inequation constr3 = new Inequation(m1, new FloatConstant(0), 3);
    Inequation constr4 = new Inequation(m2, new FloatConstant(0), 3);
    Collection<Statement> constraints = new ArrayList<Statement>();
    constraints.add(constr1);
    constraints.add(constr2);
    constraints.add(constr3);
    constraints.add(constr4);
    OptimizationProblem prob = new OptimizationProblem(1);
    prob.addAll(constraints);
    // Define targetfunction
    Term opt = m1;
    prob.setTargetFunction(opt);
    return prob;
}
Also used : Inequation(org.tweetyproject.math.equation.Inequation) Statement(org.tweetyproject.math.equation.Statement) FloatConstant(org.tweetyproject.math.term.FloatConstant) ArrayList(java.util.ArrayList) OptimizationProblem(org.tweetyproject.math.opt.problem.OptimizationProblem) Term(org.tweetyproject.math.term.Term) FloatVariable(org.tweetyproject.math.term.FloatVariable)

Aggregations

FloatConstant (org.tweetyproject.math.term.FloatConstant)69 Term (org.tweetyproject.math.term.Term)66 Variable (org.tweetyproject.math.term.Variable)40 FloatVariable (org.tweetyproject.math.term.FloatVariable)37 HashMap (java.util.HashMap)33 OptimizationProblem (org.tweetyproject.math.opt.problem.OptimizationProblem)32 IntegerConstant (org.tweetyproject.math.term.IntegerConstant)30 GeneralMathException (org.tweetyproject.math.GeneralMathException)25 ArrayList (java.util.ArrayList)20 Equation (org.tweetyproject.math.equation.Equation)18 Statement (org.tweetyproject.math.equation.Statement)15 Sum (org.tweetyproject.math.term.Sum)15 Power (org.tweetyproject.math.term.Power)13 Inequation (org.tweetyproject.math.equation.Inequation)12 Argument (org.tweetyproject.arg.dung.syntax.Argument)8 Probability (org.tweetyproject.math.probability.Probability)8 HashSet (java.util.HashSet)7 PlFormula (org.tweetyproject.logics.pl.syntax.PlFormula)7 Test (org.junit.Test)6 ProbabilisticConditional (org.tweetyproject.logics.pcl.syntax.ProbabilisticConditional)6