Search in sources :

Example 1 with MutableDouble

use of org.apache.commons.lang3.mutable.MutableDouble in project neo4j by neo4j.

the class DijkstraBidirectional method traverser.

private Traverser traverser(Node start, final Node end, PathInterest interest) {
    final MutableDouble shortestSoFar = new MutableDouble(Double.MAX_VALUE);
    final MutableDouble startSideShortest = new MutableDouble(0);
    final MutableDouble endSideShortest = new MutableDouble(0);
    PathExpander dijkstraExpander = new DijkstraBidirectionalPathExpander(expander, shortestSoFar, true, startSideShortest, endSideShortest, epsilon);
    GraphDatabaseService db = start.getGraphDatabase();
    TraversalDescription side = db.traversalDescription().expand(dijkstraExpander, stateFactory).order(new DijkstraSelectorFactory(interest, costEvaluator)).evaluator(new DijkstraBidirectionalEvaluator(costEvaluator)).uniqueness(Uniqueness.NODE_PATH);
    TraversalDescription startSide = side;
    TraversalDescription endSide = side.reverse();
    BidirectionalTraversalDescription traversal = db.bidirectionalTraversalDescription().startSide(startSide).endSide(endSide).collisionEvaluator(Evaluators.all()).collisionPolicy(new BranchCollisionPolicy() {

        @Override
        public BranchCollisionDetector create(Evaluator evaluator, Predicate<Path> pathPredicate) {
            return new DijkstraBranchCollisionDetector(evaluator, costEvaluator, shortestSoFar, epsilon, pathPredicate);
        }
    });
    lastTraverser = traversal.traverse(start, end);
    return lastTraverser;
}
Also used : WeightedPath(org.neo4j.graphalgo.WeightedPath) Path(org.neo4j.graphdb.Path) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) BranchCollisionPolicy(org.neo4j.graphdb.traversal.BranchCollisionPolicy) MutableDouble(org.apache.commons.lang3.mutable.MutableDouble) PathExpander(org.neo4j.graphdb.PathExpander) DijkstraSelectorFactory(org.neo4j.graphalgo.impl.util.DijkstraSelectorFactory) PathEvaluator(org.neo4j.graphdb.traversal.PathEvaluator) Evaluator(org.neo4j.graphdb.traversal.Evaluator) CostEvaluator(org.neo4j.graphalgo.CostEvaluator) BidirectionalTraversalDescription(org.neo4j.graphdb.traversal.BidirectionalTraversalDescription) BranchCollisionDetector(org.neo4j.graphdb.traversal.BranchCollisionDetector) DijkstraBranchCollisionDetector(org.neo4j.graphalgo.impl.util.DijkstraBranchCollisionDetector) BidirectionalTraversalDescription(org.neo4j.graphdb.traversal.BidirectionalTraversalDescription) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) DijkstraBranchCollisionDetector(org.neo4j.graphalgo.impl.util.DijkstraBranchCollisionDetector)

Example 2 with MutableDouble

use of org.apache.commons.lang3.mutable.MutableDouble in project neo4j by neo4j.

the class DijkstraBidirectional method traverser.

private Traverser traverser(Node start, final Node end, PathInterest<Double> interest) {
    final MutableDouble shortestSoFar = new MutableDouble(Double.MAX_VALUE);
    final MutableDouble startSideShortest = new MutableDouble(0);
    final MutableDouble endSideShortest = new MutableDouble(0);
    PathExpander<Double> dijkstraExpander = new DijkstraBidirectionalPathExpander(expander, shortestSoFar, true, startSideShortest, endSideShortest, epsilon);
    var transaction = context.transaction();
    TraversalDescription side = transaction.traversalDescription().expand(dijkstraExpander, stateFactory).order(new DijkstraSelectorFactory(interest, costEvaluator)).evaluator(new DijkstraBidirectionalEvaluator(costEvaluator)).uniqueness(Uniqueness.NODE_PATH);
    TraversalDescription startSide = side;
    TraversalDescription endSide = side.reverse();
    BidirectionalTraversalDescription traversal = transaction.bidirectionalTraversalDescription().startSide(startSide).endSide(endSide).collisionEvaluator(Evaluators.all()).collisionPolicy((evaluator, pathPredicate) -> new DijkstraBranchCollisionDetector(evaluator, costEvaluator, shortestSoFar, epsilon, pathPredicate));
    lastTraverser = traversal.traverse(start, end);
    return lastTraverser;
}
Also used : MutableDouble(org.apache.commons.lang3.mutable.MutableDouble) BidirectionalTraversalDescription(org.neo4j.graphdb.traversal.BidirectionalTraversalDescription) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) DijkstraBranchCollisionDetector(org.neo4j.graphalgo.impl.util.DijkstraBranchCollisionDetector) DijkstraSelectorFactory(org.neo4j.graphalgo.impl.util.DijkstraSelectorFactory) MutableDouble(org.apache.commons.lang3.mutable.MutableDouble) BidirectionalTraversalDescription(org.neo4j.graphdb.traversal.BidirectionalTraversalDescription)

Example 3 with MutableDouble

use of org.apache.commons.lang3.mutable.MutableDouble in project apex-malhar by apache.

the class SumTest method SumTest.

@Test
public void SumTest() {
    SumInt si = new SumInt();
    SumLong sl = new SumLong();
    SumFloat sf = new SumFloat();
    SumDouble sd = new SumDouble();
    Assert.assertEquals(new MutableInt(10), si.accumulate(si.defaultAccumulatedValue(), 10));
    Assert.assertEquals(new MutableInt(11), si.accumulate(new MutableInt(1), 10));
    Assert.assertEquals(new MutableInt(22), si.merge(new MutableInt(1), new MutableInt(21)));
    Assert.assertEquals(new MutableLong(10L), sl.accumulate(sl.defaultAccumulatedValue(), 10L));
    Assert.assertEquals(new MutableLong(22L), sl.accumulate(new MutableLong(2L), 20L));
    Assert.assertEquals(new MutableLong(41L), sl.merge(new MutableLong(32L), new MutableLong(9L)));
    Assert.assertEquals(new MutableFloat(9.0F), sf.accumulate(sf.defaultAccumulatedValue(), 9.0F));
    Assert.assertEquals(new MutableFloat(22.5F), sf.accumulate(new MutableFloat(2.5F), 20F));
    Assert.assertEquals(new MutableFloat(41.0F), sf.merge(new MutableFloat(33.1F), new MutableFloat(7.9F)));
    Assert.assertEquals(new MutableDouble(9.0), sd.accumulate(sd.defaultAccumulatedValue(), 9.0));
    Assert.assertEquals(new MutableDouble(22.5), sd.accumulate(new MutableDouble(2.5), 20.0));
    Assert.assertEquals(new MutableDouble(41.0), sd.merge(new MutableDouble(33.1), new MutableDouble(7.9)));
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableFloat(org.apache.commons.lang3.mutable.MutableFloat) MutableDouble(org.apache.commons.lang3.mutable.MutableDouble) MutableInt(org.apache.commons.lang3.mutable.MutableInt) Test(org.junit.Test)

Example 4 with MutableDouble

use of org.apache.commons.lang3.mutable.MutableDouble in project vcell by virtualcell.

the class SimulationWarning method analyzeDiffusion.

/**
 * make sure diffusion expressions are constants, store for later use
 * @throws ExpressionException
 */
private static Map<MembraneSubDomain, List<DiffusionValue>> analyzeDiffusion(Simulation simulation, double timeStep, IssueContext issueContext, List<Issue> issueList) throws ExpressionException {
    Map<MembraneSubDomain, List<DiffusionValue>> diffusionValuesMap = new IdentityHashMap<>();
    diffusionValuesMap.clear();
    MutableDouble value = new MutableDouble();
    MathDescription cm = simulation.getMathDescription();
    Objects.requireNonNull(cm);
    MathDescription localMath = new MathDescription(cm);
    SimulationSymbolTable symTable = new SimulationSymbolTable(simulation, 0);
    Map<MembraneSubDomain, List<DiffusionValue>> dvMap = new HashMap<>();
    double maxDiffValue = Double.MIN_VALUE;
    List<DiffusionValue> diffusionList = new ArrayList<>();
    for (SubDomain sd : localMath.getSubDomainCollection()) {
        final boolean isMembrane = sd instanceof MembraneSubDomain;
        diffusionList.clear();
        for (ParticleProperties pp : sd.getParticleProperties()) {
            String name = pp.getVariable().getName();
            Expression diffExp = pp.getDiffusion();
            Expression flattened = MathUtilities.substituteFunctions(diffExp, symTable).flatten();
            if (isConstant(flattened, value)) {
                if (isMembrane) {
                    DiffusionValue dv = new DiffusionValue(name, value.doubleValue());
                    maxDiffValue = Math.max(maxDiffValue, dv.value);
                    diffusionList.add(dv);
                }
            } else {
                String s = "Smoldyn only supports constant diffusion, " + name + " is variable";
                Issue i = new Issue(simulation, issueContext, IssueCategory.SMOLYDN_DIFFUSION, s, s, Severity.ERROR);
                issueList.add(i);
            }
        }
        if (isMembrane && !diffusionList.isEmpty()) {
            dvMap.put((MembraneSubDomain) sd, diffusionList);
        }
    }
    diffusionValuesMap.putAll(dvMap);
    MeshSpecification ms = simulation.getMeshSpecification();
    Geometry g = ms.getGeometry();
    int dim = g.getDimension();
    double minDelta = Double.MAX_VALUE;
    switch(dim) {
        case 3:
            minDelta = Math.min(minDelta, ms.getDz(true));
        // fall-through
        case 2:
            minDelta = Math.min(minDelta, ms.getDy(true));
        // fall-through
        case 1:
            minDelta = Math.min(minDelta, ms.getDx(true));
            break;
        default:
            throw new RuntimeException("Invalid dimension " + dim + " for smoldyn solver");
    }
    double minArea = minDelta * minDelta / 2;
    double limit = PRECHECK_LIMIT_ADJUST * minArea / maxDiffValue;
    boolean warn = (timeStep > limit);
    if (lg.isDebugEnabled()) {
        lg.debug("Min delta " + minDelta + ", min area " + minArea + " time limit " + limit + " timeStep " + timeStep + " -> warn = " + warn);
    }
    if (warn) {
        String s = "Time step " + timeStep + " may be too large, performing further analysis ...";
        Issue i = new Issue(simulation, issueContext, IssueCategory.SMOLYDN_DIFFUSION, s, s, Severity.WARNING);
        issueList.add(i);
    }
    lg.debug("end of diffusion analysis");
    return diffusionValuesMap;
}
Also used : MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Issue(org.vcell.util.Issue) MathDescription(cbit.vcell.math.MathDescription) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) MutableDouble(org.apache.commons.lang3.mutable.MutableDouble) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Geometry(cbit.vcell.geometry.Geometry) Expression(cbit.vcell.parser.Expression) ArrayList(java.util.ArrayList) List(java.util.List) ParticleProperties(cbit.vcell.math.ParticleProperties)

Example 5 with MutableDouble

use of org.apache.commons.lang3.mutable.MutableDouble in project gerrit by GerritCodeReview.

the class ReviewerRecommender method baseRanking.

/**
 * @param baseWeight The weight applied to the ordering of the reviewers.
 * @param query Query to match. For example, it can try to match all users that start with "Ab".
 * @param candidateList The list of candidates based on the query. If query is empty, this list is
 *     also empty.
 * @return Map of account ids that match the query and their appropriate ranking (the better the
 *     ranking, the better it is to suggest them as reviewers).
 * @throws IOException Can't find owner="self" account.
 * @throws ConfigInvalidException Can't find owner="self" account.
 */
private Map<Account.Id, MutableDouble> baseRanking(double baseWeight, String query, List<Account.Id> candidateList) throws IOException, ConfigInvalidException {
    int numberOfRelevantChanges = config.getInt("suggest", "relevantChanges", 50);
    // Get the user's last numberOfRelevantChanges changes, check reviewers
    try {
        List<ChangeData> result = queryProvider.get().setLimit(numberOfRelevantChanges).setRequestedFields(ChangeField.REVIEWER).query(changeQueryBuilder.owner("self"));
        Map<Account.Id, MutableDouble> suggestions = new LinkedHashMap<>();
        // Put those candidates at the bottom of the list
        candidateList.stream().forEach(id -> suggestions.put(id, new MutableDouble(0)));
        for (ChangeData cd : result) {
            for (Account.Id reviewer : cd.reviewers().all()) {
                if (accountMatchesQuery(reviewer, query)) {
                    suggestions.computeIfAbsent(reviewer, (ignored) -> new MutableDouble(0)).add(baseWeight);
                }
            }
        }
        return suggestions;
    } catch (QueryParseException e) {
        // Unhandled, because owner:self will never provoke a QueryParseException
        logger.atSevere().withCause(e).log("Exception while suggesting reviewers");
        return new HashMap<>();
    }
}
Also used : AccountCache(com.google.gerrit.server.account.AccountCache) FanOutExecutor(com.google.gerrit.server.FanOutExecutor) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) Inject(com.google.inject.Inject) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Strings(com.google.common.base.Strings) MutableDouble(org.apache.commons.lang3.mutable.MutableDouble) Config(org.eclipse.jgit.lib.Config) Future(java.util.concurrent.Future) ImmutableList(com.google.common.collect.ImmutableList) QueryParseException(com.google.gerrit.index.query.QueryParseException) Map(java.util.Map) ExecutorService(java.util.concurrent.ExecutorService) SuggestedReviewer(com.google.gerrit.server.change.SuggestedReviewer) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) Iterator(java.util.Iterator) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) ProjectState(com.google.gerrit.server.project.ProjectState) Account(com.google.gerrit.entities.Account) Set(java.util.Set) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) IOException(java.io.IOException) ApprovalsUtil(com.google.gerrit.server.approval.ApprovalsUtil) PluginMapContext(com.google.gerrit.server.plugincontext.PluginMapContext) ChangeField(com.google.gerrit.server.index.change.ChangeField) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) ChangeData(com.google.gerrit.server.query.change.ChangeData) Provider(com.google.inject.Provider) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) Stream(java.util.stream.Stream) ChangeQueryBuilder(com.google.gerrit.server.query.change.ChangeQueryBuilder) InternalChangeQuery(com.google.gerrit.server.query.change.InternalChangeQuery) Optional(java.util.Optional) AccountState(com.google.gerrit.server.account.AccountState) Collections(java.util.Collections) FluentLogger(com.google.common.flogger.FluentLogger) ReviewerSuggestion(com.google.gerrit.server.change.ReviewerSuggestion) Account(com.google.gerrit.entities.Account) MutableDouble(org.apache.commons.lang3.mutable.MutableDouble) ChangeData(com.google.gerrit.server.query.change.ChangeData) LinkedHashMap(java.util.LinkedHashMap) QueryParseException(com.google.gerrit.index.query.QueryParseException)

Aggregations

MutableDouble (org.apache.commons.lang3.mutable.MutableDouble)8 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Account (com.google.gerrit.entities.Account)2 SuggestedReviewer (com.google.gerrit.server.change.SuggestedReviewer)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Callable (java.util.concurrent.Callable)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 DijkstraBranchCollisionDetector (org.neo4j.graphalgo.impl.util.DijkstraBranchCollisionDetector)2 DijkstraSelectorFactory (org.neo4j.graphalgo.impl.util.DijkstraSelectorFactory)2 BidirectionalTraversalDescription (org.neo4j.graphdb.traversal.BidirectionalTraversalDescription)2 TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)2 Geometry (cbit.vcell.geometry.Geometry)1 MathDescription (cbit.vcell.math.MathDescription)1 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)1 ParticleProperties (cbit.vcell.math.ParticleProperties)1