Commit 7d314007 authored by Cedric Caffy's avatar Cedric Caffy
Browse files

[lto_rao] Implemented the RAO ShortLocateTimeFirst algorithm

parent c029470a
......@@ -18,6 +18,8 @@
#include "RAOFile.hpp"
#include <algorithm>
namespace castor { namespace tape { namespace tapeserver { namespace rao {
RAOFile::RAOFile(const uint64_t index, const FilePositionInfos & filePositionInfos):m_index(index),m_filePositionInfos(filePositionInfos) {
......@@ -47,10 +49,31 @@ FilePositionInfos RAOFile::getFilePositionInfos() const{
}
void RAOFile::addDistanceToFile(const double distance, const RAOFile& file){
m_distancesWithOtherFiles.push_back(std::make_pair(distance,file.getIndex()));
m_distancesWithOtherFiles.push_back(DistanceToFile(distance,file.getIndex()));
}
uint64_t RAOFile::getClosestFileIndex() const {
//The closest file is the one that has the lower cost
auto minElementItor = std::min_element(m_distancesWithOtherFiles.begin(), m_distancesWithOtherFiles.end());
//This method should never throw as there is always at least two files in a RAO batch
return minElementItor->getCost();
}
RAOFile::~RAOFile() {
}
RAOFile::DistanceToFile::DistanceToFile(const double cost, const uint64_t destinationFileIndex):m_cost(cost),m_destinationFileIndex(destinationFileIndex){
}
bool RAOFile::DistanceToFile::operator <(const DistanceToFile& other) const {
return m_cost < other.m_cost;
}
double RAOFile::DistanceToFile::getCost() const{
return m_cost;
}
uint64_t RAOFile::DistanceToFile::getDestinationFileIndex() const {
return m_destinationFileIndex;
}
}}}}
\ No newline at end of file
......@@ -33,8 +33,20 @@ public:
uint64_t getIndex() const;
FilePositionInfos getFilePositionInfos() const;
void addDistanceToFile(const double distance, const RAOFile & file);
uint64_t getClosestFileIndex() const;
virtual ~RAOFile();
typedef std::pair<double,uint64_t> DistanceToFile;
class DistanceToFile {
public:
DistanceToFile(const double cost, const uint64_t destinationFileIndex);
bool operator<(const DistanceToFile &other) const;
double getCost() const;
uint64_t getDestinationFileIndex() const;
private:
double m_cost;
uint64_t m_destinationFileIndex;
};
private:
uint64_t m_index;
FilePositionInfos m_filePositionInfos;
......
......@@ -68,7 +68,6 @@ namespace unitTests {
return ret;
}
};
class RAOTest: public ::testing::Test {
......
......@@ -82,14 +82,17 @@ std::vector<RAOFile> SLTFRAOAlgorithm::computeAllFilesPosition(const std::vector
for(uint64_t i = 0; i < jobs.size(); ++i){
files.push_back(RAOFile(i,m_filePositionEstimator->getFilePosition(*(jobs.at(i)))));
}
//Create a dummy file that starts at the beginning of the tape (the SLTF algorithm will start from this file)
std::unique_ptr<cta::RetrieveJob> dummyRetrieveJob = createFakeRetrieveJobForFileAtBeginningOfTape();
files.push_back(RAOFile(jobs.size(),m_filePositionEstimator->getFilePosition(*dummyRetrieveJob)));
return files;
}
void SLTFRAOAlgorithm::computeCostBetweenAllFiles(std::vector<RAOFile> & files) const {
for(uint64_t i = 0; i < files.size(); ++i){
for(unsigned int i = 0; i < files.size(); ++i){
auto & sourceFile = files.at(i);
for(uint64_t j = 0; j < files.size(); ++j){
//We don't want the distance between the same file
for(unsigned int j = 0; j < files.size(); ++j){
//We don't want the distance between the file and itself
if(i != j){
auto & destinationFile = files.at(j);
double distanceToFileJ = m_costHeuristic->getCost(sourceFile.getFilePositionInfos(),destinationFile.getFilePositionInfos());
......@@ -101,7 +104,28 @@ void SLTFRAOAlgorithm::computeCostBetweenAllFiles(std::vector<RAOFile> & files)
std::vector<uint64_t> SLTFRAOAlgorithm::performSLTF(const std::vector<RAOFile>& files) const {
//TODO
return std::vector<uint64_t>();
std::vector<uint64_t> solution;
//Start from the fake file that is at the beginning of the tape
auto firstFile = files.back();
solution.push_back(firstFile.getClosestFileIndex());
for(unsigned int i = 0; i < files.size() - 1; ++i){
solution.push_back(files.at(i).getClosestFileIndex());
}
return solution;
}
std::unique_ptr<cta::RetrieveJob> SLTFRAOAlgorithm::createFakeRetrieveJobForFileAtBeginningOfTape() const {
std::unique_ptr<cta::RetrieveJob> ret;
cta::common::dataStructures::ArchiveFile archiveFile;
cta::common::dataStructures::TapeFile tapeFile;
tapeFile.blockId = 0;
tapeFile.copyNb = 1;
tapeFile.fSeq = 0;
tapeFile.fileSize = 0;
archiveFile.tapeFiles.push_back(tapeFile);
cta::common::dataStructures::RetrieveRequest retrieveRequest;
ret.reset(new cta::RetrieveJob(nullptr,retrieveRequest,archiveFile,1,cta::PositioningMethod::ByBlock));
return ret;
}
}}}}
\ No newline at end of file
......@@ -49,11 +49,11 @@ private:
SLTFRAOAlgorithm();
std::unique_ptr<FilePositionEstimator> m_filePositionEstimator;
std::unique_ptr<CostHeuristic> m_costHeuristic;
std::vector<RAOFile> computeAllFilesPosition(const std::vector<std::unique_ptr<cta::RetrieveJob> > & jobs) const;
void computeCostBetweenAllFiles(std::vector<RAOFile> & files) const;
std::vector<uint64_t> performSLTF(const std::vector<RAOFile> & files) const;
std::unique_ptr<cta::RetrieveJob> createFakeRetrieveJobForFileAtBeginningOfTape() const;
};
}}}}
......
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