Search in sources :

Example 6 with TObjectIntHashMap

use of gnu.trove.map.hash.TObjectIntHashMap in project scheduler by btrplace.

the class CShareableResource method getWeights.

/**
 * Estimate the weight of each VMs with regards to multiple dimensions.
 * In practice, it sums the normalised size of each VM against the total capacity
 *
 * @param rp  the problem to solve
 * @param rcs the resources to consider
 * @return a weight per VM
 */
public static TObjectIntMap<VM> getWeights(ReconfigurationProblem rp, List<CShareableResource> rcs) {
    Model mo = rp.getSourceModel();
    int[] capa = new int[rcs.size()];
    int[] cons = new int[rcs.size()];
    TObjectIntMap<VM> cost = new TObjectIntHashMap<>();
    for (Node n : mo.getMapping().getAllNodes()) {
        for (int i = 0; i < rcs.size(); i++) {
            capa[i] += rcs.get(i).virtRcUsage.get(rp.getNode(n)).getUB() * rcs.get(i).ratios.get(rp.getNode(n));
        }
    }
    for (VM v : mo.getMapping().getAllVMs()) {
        for (int i = 0; i < rcs.size(); i++) {
            cons[i] += rcs.get(i).getVMAllocation(rp.getVM(v));
        }
    }
    for (VM v : mo.getMapping().getAllVMs()) {
        double sum = 0;
        for (int i = 0; i < rcs.size(); i++) {
            double ratio = 0;
            if (cons[i] > 0) {
                ratio = 1.0 * rcs.get(i).getVMAllocation(rp.getVM(v)) / capa[i];
            }
            sum += ratio;
        }
        cost.put(v, (int) (sum * 10000));
    }
    return cost;
}
Also used : TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) SatConstraint(org.btrplace.model.constraint.SatConstraint)

Example 7 with TObjectIntHashMap

use of gnu.trove.map.hash.TObjectIntHashMap in project BiomeTweaker by superckl.

the class ScriptCommandMaxSpawnPackSize method perform.

@Override
public void perform() throws Exception {
    if (this.entityClass == null) {
        EntityEventHandler.setGlobalPackSize(this.size);
        return;
    }
    Class<?> clazz;
    try {
        clazz = Class.forName(this.entityClass);
    } catch (final Exception e) {
        throw new IllegalArgumentException("Failed to load entity class: " + this.entityClass, e);
    }
    final Iterator<Biome> it = this.pack.getIterator();
    while (it.hasNext()) {
        final Biome biome = it.next();
        final TIntObjectMap<TObjectIntMap<String>> map = EntityEventHandler.getPackSizes();
        if (!map.containsKey(Biome.getIdForBiome(biome)))
            map.put(Biome.getIdForBiome(biome), new TObjectIntHashMap<String>());
        map.get(Biome.getIdForBiome(biome)).put(clazz.getName(), this.size);
    }
}
Also used : TObjectIntMap(gnu.trove.map.TObjectIntMap) Biome(net.minecraft.world.biome.Biome) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap)

Example 8 with TObjectIntHashMap

use of gnu.trove.map.hash.TObjectIntHashMap in project spf4j by zolyfarkas.

the class VMHistograms method getHeapInstanceCountsHistogram.

public static TObjectIntMap<Klass> getHeapInstanceCountsHistogram() {
    final TObjectIntMap<Klass> counts = new TObjectIntHashMap(10240);
    VM vm = sun.jvm.hotspot.runtime.VM.getVM();
    vm.getObjectHeap().iterate(new DefaultHeapVisitor() {

        @Override
        public boolean doObj(final Oop oop) {
            counts.increment(oop.getKlass());
            oop.getKlass();
            return false;
        }
    });
    return counts;
}
Also used : DefaultHeapVisitor(sun.jvm.hotspot.oops.DefaultHeapVisitor) Oop(sun.jvm.hotspot.oops.Oop) Klass(sun.jvm.hotspot.oops.Klass) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) VM(sun.jvm.hotspot.runtime.VM)

Example 9 with TObjectIntHashMap

use of gnu.trove.map.hash.TObjectIntHashMap in project OpenTripPlanner by opentripplanner.

the class LinkingTest method jaggedArrayToVertexMap.

private TObjectIntMap<String> jaggedArrayToVertexMap(int[] value, Graph g) {
    TObjectIntMap<String> ret = new TObjectIntHashMap<String>();
    for (int i = 0; i < value.length; i++) {
        Vertex v = g.getVertexById(value[i++]);
        if (!v.getLabel().startsWith("osm:node"))
            continue;
        ret.put(v.getLabel(), value[i]);
    }
    return ret;
}
Also used : SplitterVertex(org.opentripplanner.routing.vertextype.SplitterVertex) Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) LineString(com.vividsolutions.jts.geom.LineString)

Example 10 with TObjectIntHashMap

use of gnu.trove.map.hash.TObjectIntHashMap in project OpenTripPlanner by opentripplanner.

the class RoundBasedProfileRouter method route.

public void route() {
    LOG.info("access modes: {}", request.accessModes);
    LOG.info("egress modes: {}", request.egressModes);
    LOG.info("direct modes: {}", request.directModes);
    // TimeWindow could constructed in the caller, which does have access to the graph index.
    this.window = new TimeWindow(request.fromTime, request.toTime, graph.index.servicesRunning(request.date));
    // Establish search timeouts
    long searchBeginTime = System.currentTimeMillis();
    long abortTime = searchBeginTime + TIMEOUT * 1000;
    LOG.info("Finding access/egress paths.");
    // Look for stops that are within a given time threshold of the origin and destination
    // Find the closest stop on each pattern near the origin and destination
    // TODO consider that some stops may be closer by one mode than another
    // and that some stops may be accessible by one mode but not another
    ProfileStateStore store = RETAIN_PATTERNS ? new MultiProfileStateStore() : new SingleProfileStateStore();
    for (ProfileState ps : findInitialStops(false)) {
        store.put(ps);
    }
    LOG.info("Found {} initial stops", store.size());
    // we don't want to generate trips that are artificially forced to go past a transit stop.
    ROUNDS: for (int round = 0; round < MAX_ROUNDS; round++) {
        long roundStart = System.currentTimeMillis();
        LOG.info("Begin round {}; {} stops to explore", round, store.size());
        ProfileStateStore previousStore = store;
        store = RETAIN_PATTERNS ? new MultiProfileStateStore((MultiProfileStateStore) store) : new SingleProfileStateStore((SingleProfileStateStore) store);
        Set<TripPattern> patternsToExplore = Sets.newHashSet();
        // explore all of the patterns at the stops visited on the previous round
        for (TransitStop tstop : previousStore.keys()) {
            Collection<TripPattern> patterns = graph.index.patternsForStop.get(tstop.getStop());
            patternsToExplore.addAll(patterns);
        }
        LOG.info("Exploring {} patterns", patternsToExplore.size());
        // propagate all of the bounds down each pattern
        PATTERNS: for (final TripPattern pattern : patternsToExplore) {
            STOPS: for (int i = 0; i < pattern.stopVertices.length; i++) {
                if (!previousStore.containsKey(pattern.stopVertices[i]))
                    continue STOPS;
                Collection<ProfileState> statesToPropagate;
                // only propagate nondominated states
                statesToPropagate = previousStore.get(pattern.stopVertices[i]);
                // don't propagate states that use the same pattern
                statesToPropagate = Collections2.filter(statesToPropagate, new Predicate<ProfileState>() {

                    @Override
                    public boolean apply(ProfileState input) {
                        // don't reboard same pattern, and don't board patterns that are better boarded elsewhere
                        return !input.containsPattern(pattern) && (input.targetPatterns == null || input.targetPatterns.contains(pattern));
                    }
                });
                if (statesToPropagate.isEmpty())
                    continue STOPS;
                int minWaitTime = Integer.MAX_VALUE;
                int maxWaitTime = Integer.MIN_VALUE;
                // (i.e. the transfer time is different for the initial boarding than transfers)
                for (FrequencyEntry freq : pattern.scheduledTimetable.frequencyEntries) {
                    if (freq.exactTimes) {
                        throw new IllegalStateException("Exact times not yet supported in profile routing.");
                    }
                    int overlap = window.overlap(freq.startTime, freq.endTime, freq.tripTimes.serviceCode);
                    if (overlap > 0) {
                        if (freq.headway > maxWaitTime)
                            maxWaitTime = freq.headway;
                        // if any frequency-based trips are running a wait of 0 is always possible, because it could come
                        // just as you show up at the stop.
                        minWaitTime = 0;
                    }
                }
                DESTSTOPS: for (int j = i + 1; j < pattern.stopVertices.length; j++) {
                    // how long does it take to ride this trip from i to j?
                    int minRideTime = Integer.MAX_VALUE;
                    int maxRideTime = Integer.MIN_VALUE;
                    // how long does it take to get to stop j from stop i?
                    for (TripTimes tripTimes : pattern.scheduledTimetable.tripTimes) {
                        int depart = tripTimes.getDepartureTime(i);
                        int arrive = tripTimes.getArrivalTime(j);
                        if (window.includes(depart) && window.includes(arrive) && window.servicesRunning.get(tripTimes.serviceCode)) {
                            int t = arrive - depart;
                            if (t < minRideTime)
                                minRideTime = t;
                            if (t > maxRideTime)
                                maxRideTime = t;
                        }
                    }
                    /* Do the same thing for any frequency-based trips. */
                    for (FrequencyEntry freq : pattern.scheduledTimetable.frequencyEntries) {
                        TripTimes tt = freq.tripTimes;
                        int overlap = window.overlap(freq.startTime, freq.endTime, tt.serviceCode);
                        if (overlap == 0)
                            continue;
                        int depart = tt.getDepartureTime(i);
                        int arrive = tt.getArrivalTime(j);
                        int t = arrive - depart;
                        if (t < minRideTime)
                            minRideTime = t;
                        if (t > maxRideTime)
                            maxRideTime = t;
                    }
                    if (minWaitTime == Integer.MAX_VALUE || maxWaitTime == Integer.MIN_VALUE || minRideTime == Integer.MAX_VALUE || maxRideTime == Integer.MIN_VALUE)
                        // no trips in window that arrive at stop
                        continue DESTSTOPS;
                    if (minRideTime < 0 || maxRideTime < 0) {
                        LOG.error("Pattern {} travels backwards in time between stop {} and {}", pattern, pattern.stopVertices[i].getStop(), pattern.stopVertices[j].getStop());
                        continue DESTSTOPS;
                    }
                    // we've already checked to ensure we're not reboarding the same pattern
                    for (ProfileState ps : statesToPropagate) {
                        ProfileState ps2 = ps.propagate(minWaitTime + minRideTime, maxWaitTime + maxRideTime);
                        if (ps2.upperBound > CUTOFF_SECONDS)
                            continue;
                        ps2.stop = pattern.stopVertices[j];
                        ps2.accessType = Type.TRANSIT;
                        if (RETAIN_PATTERNS)
                            ps2.patterns = new TripPattern[] { pattern };
                        store.put(ps2);
                    }
                }
            }
        }
        // merge states that came from the same stop.
        if (RETAIN_PATTERNS) {
            LOG.info("Round completed, merging similar states");
            ((MultiProfileStateStore) store).mergeStates();
        }
        for (ProfileState ps : store.getAll()) {
            retainedStates.put(ps.stop, ps);
        }
        if (round == MAX_ROUNDS - 1) {
            LOG.info("Finished round {} in {} seconds", round, (System.currentTimeMillis() - roundStart) / 1000);
            break ROUNDS;
        }
        // propagate states to nearby stops (transfers)
        LOG.info("Finding transfers . . .");
        // avoid concurrent modification
        Set<TransitStop> touchedStopKeys = new HashSet<TransitStop>(store.keys());
        for (TransitStop tstop : touchedStopKeys) {
            List<Tuple2<TransitStop, Integer>> accessTimes = Lists.newArrayList();
            // find transfers for the stop
            for (Edge e : tstop.getOutgoing()) {
                if (e instanceof SimpleTransfer) {
                    SimpleTransfer t = (SimpleTransfer) e;
                    int time = (int) (t.getDistance() / request.walkSpeed);
                    accessTimes.add(new Tuple2((TransitStop) e.getToVertex(), time));
                }
            }
            // only transfer from nondominated states. only transfer to each pattern once
            Collection<ProfileState> statesAtStop = store.get(tstop);
            TObjectIntHashMap<TripPattern> minBoardTime = new TObjectIntHashMap<TripPattern>(1000, .75f, Integer.MAX_VALUE);
            Map<TripPattern, ProfileState> optimalBoardState = Maps.newHashMap();
            List<ProfileState> xferStates = Lists.newArrayList();
            // make a hashset of the patterns that stop here, because we don't want to transfer to them at another stop
            HashSet<TripPattern> patternsAtSource = new HashSet<TripPattern>(graph.index.patternsForStop.get(tstop.getStop()));
            for (ProfileState ps : statesAtStop) {
                for (Tuple2<TransitStop, Integer> atime : accessTimes) {
                    ProfileState ps2 = ps.propagate(atime.b);
                    ps2.accessType = Type.TRANSFER;
                    ps2.stop = atime.a;
                    for (TripPattern patt : graph.index.patternsForStop.get(atime.a.getStop())) {
                        // don't transfer to patterns that we can board at this stop.
                        if (patternsAtSource.contains(patt))
                            continue;
                        if (atime.b < minBoardTime.get(patt)) {
                            minBoardTime.put(patt, atime.b);
                            optimalBoardState.put(patt, ps2);
                        }
                    }
                    xferStates.add(ps2);
                }
            }
            for (Entry<TripPattern, ProfileState> e : optimalBoardState.entrySet()) {
                ProfileState ps = e.getValue();
                if (ps.targetPatterns == null)
                    ps.targetPatterns = Sets.newHashSet();
                ps.targetPatterns.add(e.getKey());
            }
            for (ProfileState ps : xferStates) {
                if (ps.targetPatterns != null && !ps.targetPatterns.isEmpty()) {
                    store.put(ps);
                }
            }
        }
        LOG.info("Finished round {} in {} seconds", round, (System.currentTimeMillis() - roundStart) / 1000);
    }
    LOG.info("Finished profile routing in {} seconds", (System.currentTimeMillis() - searchBeginTime) / 1000);
    makeSurfaces();
    LOG.info("Finished analyst request in {} seconds total", (System.currentTimeMillis() - searchBeginTime) / 1000);
}
Also used : HashSet(java.util.HashSet) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) Set(java.util.Set) RangeSet(org.opentripplanner.analyst.TimeSurface.RangeSet) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) FrequencyEntry(org.opentripplanner.routing.trippattern.FrequencyEntry) FrequencyEntry(org.opentripplanner.routing.trippattern.FrequencyEntry) Entry(java.util.Map.Entry) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) ArrayList(java.util.ArrayList) List(java.util.List) SimpleTransfer(org.opentripplanner.routing.edgetype.SimpleTransfer) HashSet(java.util.HashSet) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Tuple2(org.mapdb.Fun.Tuple2) Collection(java.util.Collection) Edge(org.opentripplanner.routing.graph.Edge) TObjectIntMap(gnu.trove.map.TObjectIntMap) Map(java.util.Map) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap)

Aggregations

TObjectIntHashMap (gnu.trove.map.hash.TObjectIntHashMap)14 TObjectIntMap (gnu.trove.map.TObjectIntMap)4 ArrayList (java.util.ArrayList)3 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)3 Entry (java.util.Map.Entry)2 ItemStack (net.minecraft.item.ItemStack)2 QualifiedModeSet (org.opentripplanner.api.parameter.QualifiedModeSet)2 FrequencyEntry (org.opentripplanner.routing.trippattern.FrequencyEntry)2 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)2 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)2 ArrayStackFilter (buildcraft.lib.inventory.filter.ArrayStackFilter)1 ItemStackKey (buildcraft.lib.misc.ItemStackKey)1 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 Ints (com.google.common.primitives.Ints)1 LineString (com.vividsolutions.jts.geom.LineString)1 TObjectIntIterator (gnu.trove.iterator.TObjectIntIterator)1 TIntSet (gnu.trove.set.TIntSet)1 TIntHashSet (gnu.trove.set.hash.TIntHashSet)1 File (java.io.File)1