Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rinde committed Dec 1, 2016
2 parents e10f184 + dfa6ec0 commit c371485
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 97 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RinLog 3.1.0
# RinLog 3.2.0
[![Javadocs](https://javadoc.io/badge/com.github.rinde/rinlog.svg?color=red)](https://javadoc.io/doc/com.github.rinde/rinlog)
[![Build Status](https://travis-ci.org/rinde/RinLog.svg)](https://travis-ci.org/rinde/RinLog)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.165142.svg)](https://doi.org/10.5281/zenodo.165142)
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.rinde</groupId>
<artifactId>rinlog</artifactId>
<version>3.1.0</version>
<version>3.2.0</version>

<name>RinLog</name>
<description>RinLog is a collection of (agent) implementations for logistics problems.</description>
Expand All @@ -12,7 +12,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<rinsim.version>4.2.0</rinsim.version>
<rinsim.version>4.3.0</rinsim.version>
<sonar.language>java</sonar.language>
<reference.version>1.0.0</reference.version>
</properties>
Expand Down
5 changes: 5 additions & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release notes

## v3.2.0
* Compatible with RinSim 4.3.0
* Added AuctionTimeStatsLogger and RoutePlannerStatsLogger
* Reauctions can now be disabled in RtSolverBidder

## v3.1.0
* Compatible with RinSim 4.2.0
* Added simulated time versions of RtSolverBidder and RtSolverRoutePlanner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,26 @@ public static <T extends Bid<T>> Builder<T> builder(Class<T> type) {
return Builder.<T>create();
}

/**
* Event types of {@link AuctionEvent}.
* @author Rinde van Lon
*/
public enum EventType {
START_AUCTION, FINISH_AUCTION, START_RE_AUCTION

/**
* Event type indicating the start of an auction.
*/
START_AUCTION,

/**
* Event type indicating the end of an auction.
*/
FINISH_AUCTION,

/**
* Event type indicating the start of a reauction.
*/
START_RE_AUCTION
}

public static class AuctionEvent extends Event {
Expand All @@ -190,13 +208,12 @@ public static class AuctionEvent extends Event {
private final Optional<Bidder<?>> winner;
private final int receivedBids;

protected AuctionEvent(Enum<?> type, Parcel p, Auctioneer a,
long auctStart, long t) {
AuctionEvent(Enum<?> type, Parcel p, Auctioneer a, long auctStart, long t) {
this(type, p, a, auctStart, t, -1);
}

protected AuctionEvent(Enum<?> type, Parcel p, Auctioneer a, long auctStart,
long t, int numBids) {
AuctionEvent(Enum<?> type, Parcel p, Auctioneer a, long auctStart, long t,
int numBids) {
super(type);
parcel = p;
auctionStartTime = auctStart;
Expand Down Expand Up @@ -312,7 +329,8 @@ void update(long time) {
if (time - auctionStartTime > maxAuctionDurationMs) {
throw new IllegalStateException(
"Auction duration for " + parcel + " exceeded threshold of "
+ maxAuctionDurationMs + " ms. Current time: " + time + ".");
+ maxAuctionDurationMs + " ms. Auction start time: "
+ auctionStartTime + ", current time: " + time + ".");
}

if (stopCondition.apply(Collections.unmodifiableSet(bids),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright (C) 2013-2016 Rinde van Lon, iMinds-DistriNet, KU Leuven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rinde.logistics.pdptw.mas.comm;

import java.util.ArrayList;
import java.util.List;

import com.github.rinde.logistics.pdptw.mas.comm.AuctionCommModel.AuctionEvent;
import com.github.rinde.rinsim.central.Measurable;
import com.github.rinde.rinsim.central.SolverTimeMeasurement;
import com.github.rinde.rinsim.core.model.DependencyProvider;
import com.github.rinde.rinsim.core.model.Model.AbstractModel;
import com.github.rinde.rinsim.core.model.ModelBuilder.AbstractModelBuilder;
import com.github.rinde.rinsim.event.Event;
import com.github.rinde.rinsim.event.Listener;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ListMultimap;

/**
* Utility for keeping track of auction related statistics. To use it, simply
* add {@link #builder()} to a simulation configuration. The statistics that are
* tracked are all finished {@link AuctionEvent}s and using
* {@link #getTimeMeasurements()} all time measurements can be collected.
* @author Rinde van Lon
*/
public class AuctionTimeStatsLogger extends AbstractModel<Bidder<DoubleBid>> {
final List<AuctionEvent> finishEvents;
private final List<Bidder<DoubleBid>> bidders;

AuctionTimeStatsLogger(AuctionCommModel<?> model) {
finishEvents = new ArrayList<>();
bidders = new ArrayList<>();

model.getEventAPI().addListener(new Listener() {
@Override
public void handleEvent(Event e) {
finishEvents.add((AuctionEvent) e);
}
}, AuctionCommModel.EventType.FINISH_AUCTION);
}

/**
* @return A multimap of {@link Bidder}s to {@link SolverTimeMeasurement}s.
*/
public ImmutableListMultimap<Bidder<?>, SolverTimeMeasurement> getTimeMeasurements() {
final ListMultimap<Bidder<?>, SolverTimeMeasurement> map =
ArrayListMultimap.create();
for (final Bidder<DoubleBid> b : bidders) {
if (b instanceof Measurable) {
map.putAll(b, ((Measurable) b).getTimeMeasurements());
}
}
return ImmutableListMultimap.copyOf(map);
}

/**
* @return All auction finish events that have occured so far.
*/
public ImmutableList<AuctionEvent> getAuctionFinishEvents() {
return ImmutableList.copyOf(finishEvents);
}

@Override
public boolean register(Bidder<DoubleBid> element) {
bidders.add(element);
return true;
}

@Override
public boolean unregister(Bidder<DoubleBid> element) {
return false;
}

/**
* @return {@link Builder} for {@link AuctionTimeStatsLogger}.
*/
public static Builder builder() {
return new AutoValue_AuctionTimeStatsLogger_Builder();
}

/**
* Builder for {@link AuctionTimeStatsLogger}.
* @author Rinde van Lon
*/
@AutoValue
public abstract static class Builder
extends AbstractModelBuilder<AuctionTimeStatsLogger, Bidder<DoubleBid>> {

private static final long serialVersionUID = 5417079781123182630L;

Builder() {
setDependencies(AuctionCommModel.class);
}

@Override
public AuctionTimeStatsLogger build(DependencyProvider dependencyProvider) {
return new AuctionTimeStatsLogger(
dependencyProvider.get(AuctionCommModel.class));
}
}

}
Loading

0 comments on commit c371485

Please sign in to comment.