-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptimized.h
65 lines (49 loc) · 2.05 KB
/
optimized.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// Created by nandgate on 12/3/2024.
//
#ifndef OPTIMIZED_H
#define OPTIMIZED_H
#include "Network.h"
#include "Cut.h"
#include <mutex>
#include <atomic>
#include <shared_mutex>
#ifndef FEASIBILITY_CONTAINER_CAPACITY
#define FEASIBILITY_CONTAINER_CAPACITY 128
#endif
#ifndef OPTIMALITY_CONTAINER_CAPACITY
#define OPTIMALITY_CONTAINER_CAPACITY 128
#endif
namespace Inavap {
using namespace std;
typedef shared_lock<shared_mutex> ReaderLock;
typedef unique_lock<shared_mutex> WriterLock;
class CutResource {
std::atomic<uint> count = std::atomic<uint>(0); // add padding to different cache line. // sum of opt and feas containers.
shared_mutex m;
// add padding to put in different cacheline.
vector<Inavap::CutContainer *> fCutContainers;
vector<Inavap::CutContainer *> oCutContainers;
public:
CutResource() = default;
/** Returns the sum of sizes of feasibility cut containers and optimality cut containers. The memory order
* of the load is set to relaxed.
* <b>The caller should not derive any ordering with this function call.</b>
*/
[[nodiscard]] uint getCount() const noexcept {return count.load(memory_order::relaxed);}
void add(pair<vector<Inavap::CutContainer *>, vector<Inavap::CutContainer *>> cuts);
[[nodiscard]] pair<vector<Inavap::CutContainer *>, vector<Inavap::CutContainer *>> get(uint nF, uint nO);
CutResource(const CutResource &other) = delete;
CutResource(CutResource &&other) = delete;
CutResource& operator=(const CutResource &other) = delete;
CutResource& operator=(CutResource &&other) = delete;
/* TODO: create destructor that frees all the cut containers */
~CutResource() {
// locking mutex not needed. Error if needed.
// clear all the cuts from the memory.
for (auto fCutContainer : fCutContainers) delete fCutContainer;
for (auto oCutContainer : oCutContainers) delete oCutContainer;
}
};
}
#endif //OPTIMIZED_H