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;
}
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);
}
}
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;
}
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;
}
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);
}
Aggregations