Commit 55347b87 authored by Cedric Caffy's avatar Cedric Caffy
Browse files

[lto_rao] Implemented the CTA cost heuristic

parent c6dd6e2b
......@@ -23,6 +23,7 @@ set(CTARAO_LIBRARY_SRCS
FilePositionEstimator.cpp
InterpolationFilePositionEstimator.cpp
RAOHelpers.cpp
CTACostHeuristic.cpp
)
add_library (ctarao SHARED
......
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2019 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CTACostHeuristic.hpp"
#include <cmath>
namespace castor { namespace tape { namespace tapeserver { namespace rao {
CTACostHeuristic::CTACostHeuristic() {
}
CTACostHeuristic::~CTACostHeuristic() {
}
double CTACostHeuristic::getCost(const FilePositionInfos& file1, const FilePositionInfos& file2) const {
double cost = 0.0;
Position endFile1Position = file1.getEndPosition();
Position startFile2Position = file2.getStartPosition();
uint64_t endFile1LPos = endFile1Position.getLPos();
uint64_t startFile2LPos = startFile2Position.getLPos();
uint32_t endFile1Wrap = endFile1Position.getWrap();
uint32_t startFile2Wrap = startFile2Position.getWrap();
uint8_t endFile1Band = file1.getEndBand();
uint8_t startFile2Band = file2.getStartBand();
uint8_t endFile1LandingZone = file1.getEndLandingZone();
uint8_t startFile2LandingZone = file2.getStartLandingZone();
uint64_t distance = std::abs(endFile1Position.getLPos() - startFile2Position.getLPos());
//TODO : Refactor with the RAOHelpers
int wrapChange = (endFile1Wrap != startFile2Wrap);
int bandChange = (endFile1Band != startFile2Band);
int landingZoneChange = (endFile1LandingZone != startFile2LandingZone);
int directionChange = ((endFile1Wrap % 2) != (startFile2Wrap % 2));
int stepBack = 0;
if(endFile1Wrap == startFile2Wrap){
if((endFile1Wrap % 2) == 0 && (startFile2LPos < endFile1LPos)){
stepBack = 1;
} else if ((endFile1Wrap % 2) == 1 && (startFile2LPos > endFile1LPos)){
stepBack = 1;
}
}
cost = 4.29 + wrapChange * 6.69 + bandChange * 3.2 + landingZoneChange * (-6.04) + directionChange * 5.22 + stepBack * 11.32 + distance * 0.0006192;
return cost;
}
}}}}
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2019 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "CostHeuristic.hpp"
namespace castor { namespace tape { namespace tapeserver { namespace rao {
class CTACostHeuristic : public CostHeuristic{
public:
CTACostHeuristic();
double getCost(const FilePositionInfos & file1, const FilePositionInfos & file2) const override;
virtual ~CTACostHeuristic();
private:
};
}}}}
......@@ -20,12 +20,6 @@
namespace castor { namespace tape { namespace tapeserver { namespace rao {
CostHeuristic::CostHeuristic() {
}
CostHeuristic::CostHeuristic(const CostHeuristic& orig) {
}
CostHeuristic::~CostHeuristic() {
}
......
......@@ -18,12 +18,19 @@
#pragma once
#include "FilePositionInfos.hpp"
namespace castor { namespace tape { namespace tapeserver { namespace rao {
class CostHeuristic {
public:
CostHeuristic();
CostHeuristic(const CostHeuristic& orig);
/**
* Compute the cost for going from the end of file1 to the beginning of file2
* @param file1 the file from which we will go from it's end position
* @param file2 the file to which we will arrive (beginning position)
* @return the value it costs for going from the end of file1 to the beginning of file2
*/
virtual double getCost(const FilePositionInfos & file1, const FilePositionInfos & file2) const = 0;
virtual ~CostHeuristic();
private:
......
......@@ -19,6 +19,7 @@
#include "SLTFRAOAlgorithm.hpp"
#include "InterpolationFilePositionEstimator.hpp"
#include "RAOHelpers.hpp"
#include "CTACostHeuristic.hpp"
namespace castor { namespace tape { namespace tapeserver { namespace rao {
......@@ -60,16 +61,16 @@ void SLTFRAOAlgorithm::Builder::initializeFilePositionEstimator() {
}
}
void SLTFRAOAlgorithm::Builder::initializeCostHeuristic() {
/*switch(m_data.getRAOAlgorithmOptions().getCostHeuristicType()){
switch(m_data.getRAOAlgorithmOptions().getCostHeuristicType()){
case RAOOptions::CostHeuristicType::cta:
{
m_algorithm->m_costHeuristic.reset(new )
m_algorithm->m_costHeuristic.reset(new CTACostHeuristic());
break;
}
}*/
default:
throw cta::exception::Exception("In SLTFRAOAlgorithm::Builder::initializeCostHeuristic() unknown type of cost heuristic.");
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment