Exemple #1
0
void BigMamaRoomManager::ReportRoundMark(unsigned int nRoomID, unsigned int nRoleID, const std::string &rMD5Code,
    unsigned int nMark, char nKeyRank, unsigned char nRound, const std::vector<char> &rRoundRank )
{
    if ( RoomRoundRank_None < nKeyRank && nKeyRank < RoomRoundRank_Max && nRound > 0 )
    {
        DanceBaseRoom *pRoom = FindRoom( nRoomID );

        if ( pRoom == NULL || !pRoom->HasStart() )
        {
            return;
        }

        std::string strCode;
        std::vector<int> vectRoundRank( rRoundRank.begin(), rRoundRank.end() );
        Formatter(strCode) << pRoom->GetCheckCode() << (int)nRound << (int)nKeyRank << nMark;

        for ( unsigned int i = 0; i < vectRoundRank.size(); ++i )
        {
            std::string strRank;
            Formatter(strRank) << vectRoundRank[i];
            strCode.append( strRank );
        }

        unsigned char szMD5Code[16] = {0};
        MDString( strCode.c_str(), szMD5Code );
        BinaryData2String( szMD5Code, sizeof(szMD5Code) ).swap( strCode );

        if ( rMD5Code != strCode )
        {
            return;
        }

        pRoom->RecvRoundMark( nRoleID, (int)pRoom->GetPlayMusicMode(), nRound, nMark, nKeyRank, vectRoundRank );
    }
}
Exemple #2
0
double 
Rand::VonNeumannSample(Function* f_, double xMin_, double xMax_, double yMax_){
  if(xMin_ >= xMax_)
    throw ValueError(Formatter() << "Rand::Sample called with xMin_ = "
                     << xMin_ << " xMax_ = "  << xMax_
                     );

  if(yMax_ <= 0)
    throw ValueError(Formatter() << "Rand::Sample called with yMax_ = "
                     << yMax_ << ". This is the maximum of the PDF (>0)"
                     );
  if(f_->GetNDims() != 1)
    throw ValueError("Von Neumann sampling only implemented for 1D histograms");

  // Von-neuman sampling
  double draw = 0;
  double fOfX = 1;
  double val  = 0;

  while(val > fOfX){
    draw = Uniform() * (xMax_ - xMin_)  + xMin_;
    fOfX = f_ -> operator()(std::vector<double>(1, draw));
    val  = Uniform() * yMax_;
  }
  return draw;
}
Exemple #3
0
	void Formatter(FormatData& formatData, const Line& value)
	{
		formatData.string.push_back(U'(');
		Formatter(formatData, value.begin);
		formatData.string.append(U", ");
		Formatter(formatData, value.end);
		formatData.string.push_back(U')');
	}
Exemple #4
0
	void Formatter(FormatData& formatData, const Quad& value)
	{
		formatData.string.push_back(U'(');
		Formatter(formatData, value.p0);
		formatData.string.append(U", ");
		Formatter(formatData, value.p1);
		formatData.string.append(U", ");
		Formatter(formatData, value.p2);
		formatData.string.append(U", ");
		Formatter(formatData, value.p3);
		formatData.string.push_back(U')');
	}
BinAxis
BinnedEDShrinker::ShrinkAxis(const BinAxis& axis_, const unsigned lowerBuff_, 
                              const unsigned upperBuff_) const{
    // no buffer no problem
    if (!lowerBuff_ && !upperBuff_)
        return axis_;

    if ((lowerBuff_  + upperBuff_) >= axis_.GetNBins())
        throw ValueError(Formatter() << "BinnedEDShrinker::Buffersize ("
                                     << lowerBuff_ << ", "  << upperBuff_ << ")" 
                                     << " exceeds number of bins (" << axis_.GetNBins() << ")");
    
    const size_t oldBinCount = axis_.GetNBins();
    const size_t newBinCount = oldBinCount - upperBuff_ - lowerBuff_;

    std::vector<double> lowEdges(newBinCount, 0);
    std::vector<double> highEdges(newBinCount, 0);

    // fill the vectors of the new edges using a simple offset
    for(size_t i = 0; i < newBinCount; i++){
        size_t equivilentOldBin = lowerBuff_ + i;
        lowEdges[i]   = axis_.GetBinLowEdge(equivilentOldBin);
        highEdges[i]  = axis_.GetBinHighEdge(equivilentOldBin);
    }
    
    return BinAxis(axis_.GetName(), lowEdges, highEdges, axis_.GetLatexName());
}
int HistogramGenerator::reportAlloc(const Resource* resource, event_ptr_t& event) {
	ResourceData* rd = resources.getData(resource);

	// Abort if the input data contains multiple resource types as histogram
	// reports can handle only single resource type.
	if (resource_type) {
		if (resource_type->type_id != resource->type_id) {
			throw std::runtime_error(Formatter() << "ERROR: multiple resources (" << resource_type->name <<
					"," << resource->name << ") detected, the results might be misleading.\n"
					"Use --filter-resource options to filter a single resource.");
		}
	}
	else resource_type = resource;

	// increase total allocation count for the resource size
	ResourceData::data_t::iterator iter = rd->allocs.find(event->res_size);
	if (iter == rd->allocs.end()) {
		// new resource size found - add alloc data for the resource size 
		std::pair<ResourceData::data_t::iterator, bool> pair = rd->allocs.insert(
				ResourceData::data_t::value_type(event->res_size, Alloc()));
		iter = pair.first;
	}
	iter->second.total++;
	return OK;
}
Exemple #7
0
void
CutLog::LogCut(size_t index_){
    if(index_ >= fCutCounts.size())
        throw NotFoundError(Formatter() << "CutLog::LogCut tried to log event as cut by non-existent cut #" << index_ );
    fCutCounts[index_]++;
    fNEvents++;
}
Exemple #8
0
			PrintBuffer operator <<(const Type& value) const
			{
				PrintBuffer buf;

				Formatter(*buf.formatData, value);

				return buf;
			}
Exemple #9
0
Symbol Semantic::getSym(std::string id) {
  for (std::list<Symbol::Map>::reverse_iterator it = vid.rbegin();
       it != vid.rend(); it++)
    if (it->find(id) != it->end())
      return (*it)[id];
  
  throw std::runtime_error(Formatter() << "symbol " << id << " should exist in current scope");
}
Exemple #10
0
T lexicalCast(const std::string &str)
{
    T value;
    if (!tryLexicalCast(str, value))
    {
        throw std::runtime_error(Formatter() << "Could not convert " << str);
    }
    return value;
}
std::pair<unsigned, unsigned>
BinnedEDShrinker::GetBuffer(size_t dim_) const{
    try{
        return fBuffers.at(dim_);
    }
    catch(const std::out_of_range&){
        throw NotFoundError(Formatter() << "BinnedEDShrinker::Requested buffer boundaries on non-existent dim " << dim_ << "!");
    }
}
Exemple #12
0
static Target castInt(Source value)
{
    if (value < std::numeric_limits<Target>::min() ||
        value > std::numeric_limits<Target>::max())
    {
        throw std::out_of_range(Formatter() << "Value " << value << " out of range");
    }
    return static_cast<Target>(value);
}
Exemple #13
0
double
Event::GetDatum(size_t index_) const{
    try{
        return fObservations.at(index_);
    }

    catch(const std::out_of_range& e_){
        throw NotFoundError(Formatter() << "Event::Attempted access on non-existent observable " << index_);
    }
}
Exemple #14
0
TileType* TileSet::at(size_t x, size_t y)
{
	size_t i = idx(x, y);
	if (i > types.size()) {
		Log::err("TileSet",
			Formatter("get(%, %): out of bounds") % x % y);
		return NULL;
	}
	return types[i];
}
Exemple #15
0
void GosuSoundInstance::pan(double attemptedPan)
{
	double pan = bound(attemptedPan, 0.0, 1.0);
	if (attemptedPan != pan) {
		Log::info("SoundInstance",
			Formatter(
				"Attempted to set pan to %, setting it to %"
			) % attemptedPan % pan
		);
	}
	instance.changePan(pan);
}
Exemple #16
0
std::string
CutLog::AsString() const{
    if (!fCutCounts.size())
        return "";

    if (fCutCounts.size() != fCutNames.size())
        throw LogicError(Formatter() << "CutLog::AsString() there are "
                         << fCutCounts.size()
                         << " cut counts and "
                         << fCutNames.size() << " names!");
    Formatter outString;
    outString << std::left
              << std::setw(15)
              << "Cut"
              << std::left
              << std::setw(15)
              << "# cut"
              << std::left
              << std::setw(9)
              << "(%)"
              << std::left
              << std::setw(15)
              << "# remaining"
              << std::left
              << std::setw(9)
              << "(%)";

    outString << "\n";
    for(size_t i = 0; i < fCutNames.size(); i++){
        outString << std::left
                  << std::setw(15)
                  << fCutNames.at(i)
                  << std::left
                  << std::setw(15)
                  << fCutCounts.at(i)
                  << std::left 
                  << std::setw(9)
                  << std::setprecision(3)
                  << fCutPercentages.at(i)                  
                  << std::left
                  << std::setw(15)
                  << fRemainderCounts.at(i)
                  << std::left
                  << std::setw(9)
                  << std::setprecision(3)
                  << fRemainderPercentages.at(i)
                  << "\n";


    }
    return outString;
}
Exemple #17
0
void GosuSoundInstance::speed(double attemptedSpeed)
{
	double speed = bound(attemptedSpeed, 0.0,
		std::numeric_limits<double>::max());
	if (attemptedSpeed != speed) {
		Log::info("SoundInstance",
			Formatter(
				"Attempted to set speed to %, setting it to %"
			) % attemptedSpeed % speed
		);
	}
	instance.changeSpeed(speed);
}
Exemple #18
0
void GosuSoundInstance::volume(double attemptedVolume)
{
	double volume = bound(attemptedVolume, 0.0, 1.0);
	if (attemptedVolume != volume) {
		Log::info("SoundInstance",
			Formatter(
				"Attempted to set volume to %, setting it to %"
			) % attemptedVolume % volume
		);
	}
	assert(0 <= conf.soundVolume && conf.soundVolume <= 100);
	instance.changeVolume(volume * conf.soundVolume / 100.0);
}
Exemple #19
0
void
Gaussian::SetParameters(const std::vector<double>& params_){
    try{
        fParameterManager.SetParameters(params_);
    }
    catch(const ParameterCountError&){
        throw ParameterCountError("Gaussian", 
                                  GetParameterCount(), params_.size(), 
                                  Formatter() << GetNDims() 
                                  << " means and sigmas"
                                  );
    }
}
int ActivityGenerator::reportEventInContext(const Resource* resource, const Context* context, event_ptr_t& event) {
	ResourceData* rd = resources.getData(resource);
	ContextData* cd = rd->getData(context);
	if (!cd->file_allocs) {
		// create data files for new context
		cd->file_rate = plotter.createFile(Formatter() << resource->name << " (rate:" << context->name << ")");
		cd->file_allocs = plotter.createFile(Formatter() << resource->name << " (allocs:" << context->name << ")");
		cd->file_frees = plotter.createFile(Formatter() << resource->name << " (frees:" << context->name << ")");
	}

	if (activity_step == 0) activity_step = event->timestamp;
	timestamp_t timestamp = activity_step + slice_step;
	// process timeslice if the event timestamp is outside it
	if (timestamp <= event->timestamp) {
		cd->processSlice(timestamp, slice_value);
		updateRangeX(timestamp);
		updateRangeY(cd);
		activity_step = timestamp;
	}
	cd->addEvent(event);
	return OK;
}
__inline
static void ScoreLineQIBSpecDialog_RefleshUnit(HWND listWnd, int i, int win, int lose)
{
	Minimal::ProcessHeapString itemstr;

	LVITEM item;
	item.mask = LVIF_TEXT;

	int sum = win + lose;
	// 対戦数
	itemstr = Formatter(_T("%d"), sum);
	item.iItem = i;
	item.iSubItem = 1;
	item.pszText = static_cast<LPTSTR>(itemstr);
	ListView_SetItem(listWnd, &item);
	// 勝ち
	itemstr = Formatter(_T("%d"), win);
	item.iSubItem = 2;
	item.pszText = static_cast<LPTSTR>(itemstr);
	ListView_SetItem(listWnd, &item);
	// 負け
	itemstr = Formatter(_T("%d"), lose);
	item.iSubItem = 3;
	item.pszText = static_cast<LPTSTR>(itemstr);
	ListView_SetItem(listWnd, &item);
	// 勝率
	int winningRate = ::MulDiv(win, g_winningRatePrecision, sum ? sum : 1);
	itemstr = Formatter((g_highPrecisionRateEnabled ? _T("%d.%01d%%") : _T("%d%%")), winningRate / g_winningRateFp, winningRate % g_winningRateFp);
	item.iSubItem = 4;
	item.pszText = static_cast<LPTSTR>(itemstr);
	ListView_SetItem(listWnd, &item);

	// パラメータの勝率フィールドを更新
	item.mask = LVIF_PARAM;
	item.iSubItem = 0;
	ListView_GetItem(listWnd, &item);
	LVPARAMFIELD(item.lParam).winningRate = sum ? winningRate - g_winningRatePrecision / 2 : 0;
	ListView_SetItem(listWnd, &item);
}
Exemple #22
0
void
FitResult::Print() const{
    if(fParameterNames.size() != fBestFit.size())
        throw NotFoundError(Formatter() << "Expected one name for each parameter - got " 
                            << fParameterNames.size() << " names and " << fBestFit.size() << " params"
                            );

    std::cout << "Fit Result: " << std::endl;
    for(size_t i = 0; i < fParameterNames.size(); i++){
        std::cout << fParameterNames.at(i) << "\t" 
                  << fBestFit.at(i)
                  << std::endl;
    }        
}
Exemple #23
0
ROOTNtuple::ROOTNtuple(const std::string& fileName_, const std::string& treeName_){
    fROOTFile = new TFile(fileName_.c_str());

    if (fROOTFile->IsZombie()){
        delete fROOTFile;
        throw IOError("ROOTNtuple::File Does not Exist! or is Zombie " + fileName_);
    }

    fNtuple = dynamic_cast<TNtuple*>(fROOTFile -> Get(treeName_.c_str()));

    if(!fNtuple){
        delete fROOTFile;
        throw IOError(Formatter()<<"ROOTNtuple::Tree does not exist, or isn't an ntuple! tree : " << treeName_ << ", filename: "<<fileName_);
    }        

}
Exemple #24
0
void Processor::registerFree(int index, context_t context, timestamp_t timestamp,
					const char* res_type, resource_id_t res_id) {
	resource_map_t::iterator iter = res_type ? resource_registry.find(res_type) : resource_registry.begin();
	if (iter == resource_registry.end()) {
		throw std::runtime_error(Formatter() << "Unknown resource type: " << res_type);
	}
	ResourceRegistry* registry = iter->second.get();
	// apply resource filter
	const std::string& resource_filter = Options::getInstance()->getResourceFilter();
	if (!resource_filter.empty() && resource_filter != registry->resource.name) return;

	event_ptr_t event(new EventFree(index, context, timestamp, res_id, 0));
	// validate event upon specified filters
	if (!FilterManager::getInstance()->validate(event.get())) return;

	// find the allocation event for the resource to be freed in local cache.
	event_ptr_t alloc_event;
	int rc = registry->registerFree(event, alloc_event);
	if (rc != ResourceRegistry::BLOCK_SCOPE) {
		event->res_size = alloc_event->res_size;
	}
	// only process deallocation events that are done for resources allocated in our scope
	if (rc > 0) {
		for (generator_list_t::iterator iter = generators.begin(); iter != generators.end();) {
			ReportGenerator* generator = iter->get();
			// report the generic allocation event
			if (generator->reportFree(&registry->resource, event, alloc_event) == ReportGenerator::ABORT) {
				// remove generator if the event reporting failed and generator cannot continue
				generator_list_t::iterator iter_del = iter++;
				generators.erase(iter_del);
				continue;
			}
			if (!context_registry.empty()) {
				// report the allocation event in matching contexts.
				for (context_map_t::iterator ctx_iter = context_registry.begin(); ctx_iter != context_registry.end(); ctx_iter++) {
					if (ctx_iter->second.get()->id & context) {
						generator->reportFreeInContext(&registry->resource, ctx_iter->second.get(), event, alloc_event);
					}
				}
				if (!context) generator->reportFreeInContext(&registry->resource, &context_none, event, alloc_event);
			}
			iter++;
		}
	}
}
static void ScoreLineQIBSpecDialog_InitCaption(HWND hDlg, SCORELINE_FILTER_DESC &fltCustom)
{
	Minimal::ProcessHeapString title;

	title = _T("詳細 - ");
	SYSTEMTIME loctime;
	for (int i = 1; i < SCORELINE_FILTER__MAX; i <<= 1) {
		switch(fltCustom.mask & i) {
			case SCORELINE_FILTER__P1ID:
				title += 
					Formatter(_T("with %s "), 
						TH135AddrGetCharName(fltCustom.p1id)->abbr);
				break;
			case SCORELINE_FILTER__P2ID:
				title += 
					Formatter(_T("vs %s "), 
						TH135AddrGetCharName(fltCustom.p2id)->abbr);
				break;
			case SCORELINE_FILTER__P1NAME:
				title += 
					Formatter(_T("1P[%s] "), fltCustom.p1name);
				break;
			case SCORELINE_FILTER__P2NAME:
				title += 
					Formatter(_T("2P[%s] "), fltCustom.p2name);
				break;
			case SCORELINE_FILTER__TIMESTAMP_BEGIN:
				::FileTimeToSystemTime(
					(LPFILETIME)&fltCustom.t_begin, &loctime);
				title += 
					Formatter(_T("%d/%02d/%02dから"), 
						loctime.wYear, loctime.wMonth, loctime.wDay);
				break;
			case SCORELINE_FILTER__TIMESTAMP_END:
				::FileTimeToSystemTime(
					(LPFILETIME)&fltCustom.t_end, &loctime);
				title += 
					Formatter(_T("%d/%02d/%02dまで"), 
						loctime.wYear, loctime.wMonth, loctime.wDay);
				break;
			case SCORELINE_FILTER__LIMIT:
				title += Formatter(_T("最近%d戦"), fltCustom.limit);
				break;
		}
	}
	::SetWindowText(hDlg, title);
}
Exemple #26
0
void Processor::registerAlloc(int index, context_t context, timestamp_t timestamp,
					const char* res_type, resource_id_t res_id, size_t res_size) {
	resource_map_t::iterator iter = res_type ? resource_registry.find(res_type) : resource_registry.begin();
	if (iter == resource_registry.end()) {
		throw std::runtime_error(Formatter() << "Unknown resource type: " << res_type);
	}
	ResourceRegistry* registry = iter->second.get();
	// apply resource filter
	const std::string& resource_filter = Options::getInstance()->getResourceFilter();
	if (!resource_filter.empty() && resource_filter != registry->resource.name) return;
	// create new event
	event_ptr_t event(new EventAlloc(index, context, timestamp, res_id, res_size));
	// validate event upon specified filters
	if (!FilterManager::getInstance()->validate(event.get())) return;

	// register event in local cache
	event_ptr_t old_event;
	int rc = registry->registerAlloc(event, old_event);
	// TODO: FIRE_EXISTS is returned if an event with the same id was already registered
	// probably would be good to show some warning message or something.
	if (rc > 0) {
		for (generator_list_t::iterator iter = generators.begin(); iter != generators.end(); ) {
			ReportGenerator* generator = iter->get();
			// report the generic allocation event
			if (generator->reportAlloc(&registry->resource, event) == ReportGenerator::ABORT) {
				// remove generator if the event reporting failed and generator cannot continue
				generator_list_t::iterator iter_del = iter++;
				generators.erase(iter_del);
				continue;
			}
			if (!context_registry.empty()) {
				// report the allocation event in matching contexts.
				for (context_map_t::iterator ctx_iter = context_registry.begin(); ctx_iter != context_registry.end(); ctx_iter++) {
					if (ctx_iter->second.get()->id & context) {
						generator->reportAllocInContext(&registry->resource, ctx_iter->second.get(), event);
					}
				}
				if (!context) generator->reportAllocInContext(&registry->resource, &context_none, event);
			}
			iter++;
		}
	}
}
Exemple #27
0
    T run(T start_value) {
        /*
         * Perform a recursive search to find the boundary of interest, by
         * successively evaluating potential values.  After each evaluation, the
         * `_next_after_bad` and `_next_after_good` methods are used to determine
         * the next value to try.

         * __NB__ TODO: Look up terminology for recursive strategies in
         * "Structured Parallel Programming".  They provide a term for what I call
         * `exit` here.

         * The recursive calls exit when the proposed test value is the same as
         * the most-recently tested value that failed the evaluation.  In this
         * case, we know that we have encountered the transition from `good` to
         * `bad`, _i.e., we have found the boundary_.
         */
        this->iteration_++;
        if (this->iteration_ >= this->max_iterations_) {
            throw std::runtime_error(Formatter() << "Maximum number of iterations ("
                                     << this->max_iterations_ << ") reached.");
        }
        if (this->good_found_ && this->bad_ == start_value) {
            /*
             * We have arrived back at the most-recently-failed value, so it's
             * time to stop, returning the lowest-successful value we found
             * along the way.
             */
            return this->good_;
        }
        bool result = this->evaluate(start_value);
        if (!result) {
            this->bad_ = start_value;
            return this->run(this->next_after_bad(start_value));
        } else {
            this->good_found_ = true;
            this->good_ = start_value;
            return this->run(this->next_after_good(start_value));
        }
    }
Exemple #28
0
void TraceData::scanMemoryAreas()
{
	std::ifstream file_maps(filename_maps.c_str());
	if (file_maps.fail()) {
		throw std::ios_base::failure(Formatter() << "Failed to open file: " << filename_maps);
	}
	char buffer[PATH_MAX];
	while (true) {
		file_maps.getline(buffer, sizeof(buffer));
		if (file_maps.eof()) break;
		unsigned long from, to;
		char rights[16];
		char path[PATH_MAX];
		int n = sscanf(buffer, "%lx-%lx %[^ ] %[^ ] %[^ ] %[^ ] %[^ ]",
			       &from, &to, rights, path, path, path, path);
		if (n >= 3) {
			if (n < 7) path[0] = '\0';
			void* ptr = getPageflagsData(from, to);
			addMemoryArea(from, to, static_cast<pageflags_data_t*>(ptr), path, buffer);
		}
	}
}
Exemple #29
0
double Shift::calcCost(bool print){
    double trailerCost = trailer_->getDistanceCost();
    double driverCost = driver_->getTimeCost();
    double distance = 0;
    double time = 0;
    int maxCapacity = 0;
    int negativeQuantity = 0;
    int arrivalTime = 0;//tempo de chegada + setup time + tempo de viagem
    Base *standardBase = NULL;
    double distanceTime = 0; // guarda o tempo para o arrivalTime

    if((int)stops_.size() >= 2){
        for(int i=0; i<(int)stops_.size() - 1; i++){
            distance = InputData::getDistance(stops_.at(i)->getLocation()->getIndex(),stops_.at(i+1)->getLocation()->getIndex());
        }
        distance = InputData::getDistance(stops_.at(stops_.size()-1)->getLocation()->getIndex(),stops_.at(0)->getLocation()->getIndex());
    }
    time = finalInstant_ - initialInstant_;

    //procurando inviabilidade na solução

    for(int i=0; i<(int)stops_.size(); i++){
        if(stops_.at(i)->getQuantity() > trailer_->getCapacity())
            maxCapacity++;

        if(stops_.at(i)->getQuantity() < 0){
            negativeQuantity++;
        }

        if(instanceof<Customer>(stops_.at(i)->getLocation())){
            if(stops_.at(i) == stops_.at(i+1) && i < stops_.size() - 1){
                throw std::runtime_error(Formatter() << "Error: " << Penalties::toString(STOP_LOAD_LEVEL_CHANGED) << "  " << stops_.at(i));
            }

            if(std::find(((Customer*)stops_.at(i)->getLocation())->getAllowedTrailers()->begin(), ((Customer*)stops_.at(i)->getLocation())->getAllowedTrailers()->end(), trailer_) != ((Customer*)stops_.at(i)->getLocation())->getAllowedTrailers()->end()){}
            else{
                throw std::runtime_error(Formatter() << "Error: " << Penalties::toString(CUSTOMER_TRAILER_COMPATIBILITY) << "  "<< trailer_->getIndex() << "  "<< stops_.at(i)->getLocation()->getIndex());
            }
        }

        //trata o arrivalTime
        if(i == 0){
            distanceTime += InputData::getTime(stops_.at(i)->getLocation()->getIndex(), stops_.at(i+1)->getLocation()->getIndex());
        }
        if(i > 0 && i < stops_.size()-1){
            if(instanceof<Source>(stops_.at(i)->getLocation())){
                distanceTime += ((Source*)stops_.at(i)->getLocation())->getSetupTime() + InputData::getTime(stops_.at(i)->getLocation()->getIndex(), stops_.at(i+1)->getLocation()->getIndex());
            }else if(instanceof<Customer>(stops_.at(i)->getLocation())){
                distanceTime += ((Customer*)stops_.at(i)->getLocation())->getSetupTime() + InputData::getTime(stops_.at(i)->getLocation()->getIndex(), stops_.at(i+1)->getLocation()->getIndex());
            }
        }
        if(distanceTime < stops_.at(i+1)->getArriveTime()){
            arrivalTime++;
        }
    }

    if(std::find(driver_->getTrailers()->begin(), driver_->getTrailers()->end(), trailer_) != driver_->getTrailers()->end()){}
    else{
        throw std::runtime_error(Formatter() << "Error: " << Penalties::toString(TRAILER_DRIVER_COMPATIBILITY) << "  "<< this);
    }

    cost_ =  trailerCost * distance * Penalties::getValue(TRAILER_COST_MULTIPLIER) +
            driverCost * time * Penalties::getValue(DRIVER_COST_MULTIPLIER) +
            maxCapacity * Penalties::getValue(TRAILER_MAX_CAPACITY) +
            negativeQuantity * Penalties::getValue(TRAILER_NON_NEGATIVE_QUANTITY) +
            arrivalTime * Penalties::getValue(STOP_ARRIVAL_TIME);

    if(print){
        if(trailerCost > 0){
            Formatter() << Penalties::toString(TRAILER_COST_MULTIPLIER) <<": "<< trailerCost<<"\n";
        }
        if(driverCost > 0){
            Formatter() << Penalties::toString(DRIVER_COST_MULTIPLIER) <<": "<< driverCost<<"\n";
        }
        if(maxCapacity > 0){
            Formatter() << Penalties::toString(TRAILER_MAX_CAPACITY) <<": "<< maxCapacity<<"\n";
        }
        if(negativeQuantity > 0){
            Formatter() << Penalties::toString(TRAILER_NON_NEGATIVE_QUANTITY) <<": "<< negativeQuantity<<"\n";
        }
        if(arrivalTime > 0){
            Formatter() << Penalties::toString(STOP_ARRIVAL_TIME) <<": "<< arrivalTime<<"\n";
        }
    }

    return cost_;

}
static void ScoreLineQIBSpecDialog_Reflesh(HWND hDlg)
{
	Minimal::ProcessHeapArrayT<int>itemIdMap(TH135AddrGetCharCount());

	ScoreLine_Enter();

	SCORELINE_FILTER_DESC *fltCustom = reinterpret_cast<SCORELINE_FILTER_DESC *>(GetProp(hDlg, PROP_FILTER));
	if (!fltCustom)
		goto exception;
	if (!ScoreLine_QueryTrackRecord(*fltCustom))
		goto exception;

	BOOL trDirLeft = reinterpret_cast<BOOL>(GetProp(hDlg, PROP_TRDIRLEFT));

	HWND listWnd = GetDlgItem(hDlg, IDC_LIST_SCORELINE);

	// 項目のLPARAMからIDマップを動的生成
	// GetProp静的スタイルはソートや後処理が面倒くさい
	LVITEM lvitem;
	lvitem.mask = LVIF_PARAM;
	lvitem.iSubItem = 0;
	for (size_t i = 0; i < itemIdMap.GetSize(); ++i) {
		lvitem.iItem = i;
		ListView_GetItem(listWnd, &lvitem);
		itemIdMap[i] = LVPARAMFIELD(lvitem.lParam).charId;
	}

	int sumWinAll, sumLoseAll;
	sumWinAll = sumLoseAll = 0;
	for (int i = 0; i < TH135AddrGetCharCount(); ++i) {
		int sumWin, sumLose;
		sumWin = sumLose = 0;
		for (int j = 0; j < TH135AddrGetCharCount(); ++j) {
			sumWin  += !trDirLeft ? ScoreLine_Read(itemIdMap[i], j, 0) : ScoreLine_Read(j, itemIdMap[i], 0);
			sumLose += !trDirLeft ? ScoreLine_Read(itemIdMap[i], j, 1) : ScoreLine_Read(j, itemIdMap[i], 1);
		}
		sumWinAll  += sumWin;
		sumLoseAll += sumLose;
		ScoreLineQIBSpecDialog_RefleshUnit(listWnd, i, sumWin, sumLose);
	}
	ScoreLineQIBSpecDialog_RefleshUnit(listWnd, TH135AddrGetCharCount() + 1, sumWinAll, sumLoseAll);

	LVITEM item;
	item.mask = LVIF_TEXT;

	// 過去50戦勝率(個別)
	{
		Minimal::ProcessHeapString itemstr;

		sumWinAll = sumLoseAll = 0;
		SCORELINE_FILTER_DESC filterDesc = *fltCustom;
		filterDesc.mask |= SCORELINE_FILTER__P2ID | SCORELINE_FILTER__LIMIT;
		filterDesc.limit = 50;
		for (int i = 0; i < TH135AddrGetCharCount(); ++i) {
			filterDesc.p2id = itemIdMap[i];
			if (!ScoreLine_QueryTrackRecord(filterDesc))
				goto exception;

			int sumWin, sumLose, sum;
			sumWin = sumLose = 0;
			for (int j = 0; j < TH135AddrGetCharCount(); ++j) {
				sumWin  += !trDirLeft ? ScoreLine_Read(itemIdMap[i], j, 0) : ScoreLine_Read(j, itemIdMap[i], 0);
				sumLose += !trDirLeft ? ScoreLine_Read(itemIdMap[i], j, 1) : ScoreLine_Read(j, itemIdMap[i], 1);
			}
			sum = sumWin + sumLose;
			int winningRate = ::MulDiv(sumWin, g_winningRatePrecision, sum ? sum : 1);
			itemstr = Formatter((g_highPrecisionRateEnabled ? _T("(%d.%01d%%)") : _T("(%d%%)")), winningRate / g_winningRateFp, winningRate % g_winningRateFp);
			item.iItem = i;
			item.iSubItem = 5;
			item.pszText = static_cast<LPTSTR>(itemstr);
			ListView_SetItem(listWnd, &item);
		}
	}

	// 過去30/50/100戦勝率
	int limits[] = { 30, 50, 100 };
	for (int h = 0; h < _countof(limits); ++h) {
		Minimal::ProcessHeapString itemstr;

		sumWinAll = sumLoseAll = 0;
		SCORELINE_FILTER_DESC filterDesc = *fltCustom;
		if ((filterDesc.mask & SCORELINE_FILTER__LIMIT) == 0 || filterDesc.limit > limits[h]) {
			filterDesc.mask |= SCORELINE_FILTER__LIMIT;
			filterDesc.limit = limits[h];
		}
		if (!ScoreLine_QueryTrackRecord(filterDesc))
			goto exception;
		for (int i = 0; i < TH135AddrGetCharCount(); ++i) {
			int sumWin, sumLose;
			sumWin = sumLose = 0;
			for (int j = 0; j < TH135AddrGetCharCount(); ++j) {
				sumWin  += ScoreLine_Read(j, itemIdMap[i], 0);
				sumLose += ScoreLine_Read(j, itemIdMap[i], 1);
			}
			sumWinAll  += sumWin;
			sumLoseAll += sumLose;
		}
		ScoreLineQIBSpecDialog_RefleshUnit(listWnd, TH135AddrGetCharCount() + 2 + h, sumWinAll, sumLoseAll);
	}

	ScoreLine_Leave(false);
	return;

exception:
	ScoreLine_Leave(true);
	MessageBox(hDlg, _T("戦績表示の更新に失敗しました"), NULL, MB_OK | MB_ICONSTOP);
}