All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.btrplace.scheduler.choco.DefaultParameters Maven / Gradle / Ivy

Go to download

Implementation of the VM scheduler that use the Constraint Programming solver CHOCO to compute solutions.

The newest version!
/*
 * Copyright  2022 The BtrPlace Authors. All rights reserved.
 * Use of this source code is governed by a LGPL-style
 * license that can be found in the LICENSE.txt file.
 */

package org.btrplace.scheduler.choco;

import org.btrplace.plan.ReconfigurationPlan;
import org.btrplace.scheduler.choco.constraint.ChocoMapper;
import org.btrplace.scheduler.choco.duration.DurationEvaluators;
import org.btrplace.scheduler.choco.transition.TransitionFactory;
import org.btrplace.scheduler.choco.view.ChocoView;
import org.btrplace.scheduler.choco.view.DefaultAliasedCumulatives;
import org.btrplace.scheduler.choco.view.DefaultCumulatives;
import org.btrplace.scheduler.choco.view.VectorPacking;
import org.chocosolver.memory.IEnvironment;
import org.chocosolver.memory.trailing.EnvironmentTrailing;
import org.chocosolver.solver.Settings;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.BiConsumer;

/**
 * Default implementation of {@link Parameters}.
 * 
    *
  • repair mode is disabled
  • *
  • no time limit
  • *
  • a default horizon of 1 hour
  • *
  • the transition factory comes from {@link org.btrplace.scheduler.choco.transition.TransitionFactory#newBundle()}
  • *
  • the duration evaluator is {@link org.btrplace.scheduler.choco.duration.DurationEvaluators#newBundle()}
  • *
  • the api to choco element mapper is {@link ChocoMapper#newBundle()}
  • *
  • the {@link org.btrplace.scheduler.choco.view.Packing} constraint is {@link org.btrplace.scheduler.choco.view.VectorPacking}
  • *
  • the {@link org.btrplace.scheduler.choco.view.Cumulatives} view is {@link org.btrplace.scheduler.choco.view.DefaultCumulatives}
  • *
  • the {@link org.btrplace.scheduler.choco.view.AliasedCumulatives} view is {@link org.btrplace.scheduler.choco.view.DefaultAliasedCumulatives}
  • *
  • The {@link IEnvironment} is the default choco trailing environment. For large scale experiment, use
  • *
  • The setting for choco makes {@link Settings#checkDeclaredConstraints()} returns false and prevent sum decomposition.
  • *
* * @author Fabien Hermenier */ public class DefaultParameters implements Parameters { private ChocoMapper mapper; private TransitionFactory amf; private EnvironmentFactory envf; private boolean optimize = false; private long seed = 0; private final List> views; /** * No time limit by default. */ private int timeLimit = -1; private boolean repair = false; private DurationEvaluators durationEvaluators; private final List> solutionListeners; /** * Default horizon is one hour. */ private int maxEnd = 3600; private int verbosityLevel; private Settings chocoSettings; /** * New set of parameters. * This provides {@link ChocoMapper#newBundle()}, {@link TransitionFactory#newBundle()}, * {@link DurationEvaluators#newBundle()}. */ public DefaultParameters() { this(ChocoMapper.newBundle(), DurationEvaluators.newBundle(), TransitionFactory.newBundle()); } /** * New parameters where the supported constraints/views, duration evaluators and transitions are provided. * * @param mapper the supported constraints/views. * @param dev the duration evaluator. * @param tf the supported transitions. */ public DefaultParameters(final ChocoMapper mapper, final DurationEvaluators dev, final TransitionFactory tf) { this.mapper = mapper; this.durationEvaluators = dev; this.amf = tf; envf = mo -> new EnvironmentTrailing(); //Default solver views views = new ArrayList<>(); views.add(VectorPacking.class); views.add(DefaultCumulatives.class); views.add(DefaultAliasedCumulatives.class); solutionListeners = new ArrayList<>(); chocoSettings = Settings.prod() .setMinCardinalityForSumDecomposition(10000) .setCloneVariableArrayInPropagator(false); } /** * New parameters that do not provide any extensions. * * @return the created parameters. */ public static Parameters trimmed() { return new DefaultParameters(new ChocoMapper(), new DurationEvaluators(), new TransitionFactory()); } /** * Copy constructor for the parameters. * * @param ps the parameters to copy */ public DefaultParameters(Parameters ps) { seed = ps.getRandomSeed(); amf = ps.getTransitionFactory(); optimize = ps.doOptimize(); seed = ps.getRandomSeed(); timeLimit = ps.getTimeLimit(); repair = ps.doRepair(); durationEvaluators = ps.getDurationEvaluators(); maxEnd = ps.getMaxEnd(); verbosityLevel = ps.getVerbosity(); views = new ArrayList<>(ps.getChocoViews()); mapper = ps.getMapper(); envf = ps.getEnvironmentFactory(); solutionListeners = new ArrayList<>(ps.solutionListeners()); chocoSettings = ps.chocoSettings(); } @Override public DefaultParameters doRepair(boolean b) { repair = b; return this; } @Override public boolean doRepair() { return repair; } @Override public DefaultParameters doOptimize(boolean b) { optimize = b; return this; } @Override public boolean doOptimize() { return optimize; } @Override public DefaultParameters setRandomSeed(long s) { seed = s; return this; } @Override public long getRandomSeed() { return seed; } @Override public DefaultParameters setTimeLimit(int t) { timeLimit = t; return this; } @Override public int getTimeLimit() { return timeLimit; } @Override public ChocoMapper getMapper() { return mapper; } @Override public DefaultParameters setMapper(ChocoMapper map) { mapper = map; return this; } @Override public DurationEvaluators getDurationEvaluators() { return durationEvaluators; } @Override public DefaultParameters setDurationEvaluators(DurationEvaluators dev) { durationEvaluators = dev; return this; } @Override public DefaultParameters setMaxEnd(int end) { maxEnd = end; return this; } @Override public int getMaxEnd() { return maxEnd; } @Override public DefaultParameters setVerbosity(int lvl) { verbosityLevel = lvl; return this; } @Override public int getVerbosity() { return verbosityLevel; } @Override public DefaultParameters setTransitionFactory(TransitionFactory f) { this.amf = f; return this; } @Override public TransitionFactory getTransitionFactory() { return this.amf; } @Override public boolean addChocoView(Class c) { try { c.getDeclaredConstructor(); return views.add(c); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("No default constructor available for '" + c.getName() + "'", e); } } @Override public boolean removeChocoView(Class v) { return views.remove(v); } @Override public List> getChocoViews() { return Collections.unmodifiableList(views); } @Override public EnvironmentFactory getEnvironmentFactory() { return envf; } @Override public Parameters setEnvironmentFactory(EnvironmentFactory f) { envf = f; return this; } @Override public Settings chocoSettings() { return chocoSettings; } @Override public Parameters chocoSettings(Settings s) { chocoSettings = s; return this; } @Override public Parameters addSolutionListener(BiConsumer consumer) { this.solutionListeners.add(consumer); return this; } @Override public List> solutionListeners() { return Collections.unmodifiableList(solutionListeners); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy