Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ file(COPY ${DATAFILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

include_directories("${PROJECT_SOURCE_DIR}/src/")
file(GLOB SOURCES "${PROJECT_SOURCE_DIR}/src/*.cpp")
add_executable(unit_commitment "${PROJECT_SOURCE_DIR}/src/main.cpp" ${SOURCES})
add_executable(unit_commitment "main.cpp" ${SOURCES} src/dijkstra.cpp src/economic_dispatch.cpp src/economic_dispatch.h src/lambdaFunction.cpp)
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@

## Compiler info
<img width="537" src="https://github.com/ISU-CS4488-S21/Capstone-Project/blob/develop/documents/compiler.png">

# Unit Testing a code on CLion using GoogleTest

## Load CMakeLists
Expand Down
Binary file removed documents/Rough System Diagram.pdf
Binary file not shown.
Binary file removed documents/Unit Commitment.pdf
Binary file not shown.
Binary file removed documents/compiler.png
Binary file not shown.
43 changes: 22 additions & 21 deletions src/main.cpp → main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,7 @@ int main() {
}
}

// Verify that genCombos contains sub-vectors containing each possible off/on combination
for(const auto& combo : genCombos) {
for(auto gen : combo) {
std::cout << "gt: " << gen.getGeneratorType() << " on: " << gen.getIsOn() << '\t';
}
std::cout << std::endl;
}


// Narrow down to only on generators
// Narrow down to only on generators -- Is this needed?
std::vector<std::vector<Generator>> onGenCombos;
std::vector<Generator> onGens;
for(const auto& combo : genCombos){
Expand All @@ -103,21 +94,31 @@ int main() {
onGens.push_back(gen);
}
}
if(onGens.size() > 0){
if(!onGens.empty()){
onGenCombos.push_back(onGens);
}
onGens.clear();
}


// Get Node Costs
std::cout << "Load @ 1500" << std::endl;
for(const auto& combo : onGenCombos){
//for(auto load : predictedLoad){
//Economic_Dispatch().lambdaFunction(load,combo,combo.size());
//}
std::cout << " Lambda Cost: " << Economic_Dispatch().lambdaFunction(1500,combo,combo.size()) << std::endl;

// Feed this to the pathfinding algorithm
Economic_Dispatch dispatch;
std::vector<std::vector<double>> lambdas;
for(auto &genCombo : onGenCombos) {
std::vector<double> temp;
temp.reserve(predictedLoad.size());
for(auto load : predictedLoad) {
temp.push_back(dispatch.lambdaFunction(load, genCombo, 0));
}
lambdas.emplace_back(temp);
}

// Print out the result of running the lambda function for each combo list. Something seems off with the numbers.
for(const auto& lambda : lambdas) {
for(auto cost : lambda) {
std::cout << cost << '\t';
}
std::cout << std::endl;
}

return 0;
}
49 changes: 28 additions & 21 deletions src/generator.cpp → src/Generator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "generator.h"
#include "Generator.h"
#include <cmath>
#include <ctime>
#include <stdlib.h>

/**
* @author Marcus Goeckner
Expand All @@ -13,58 +15,63 @@
* @param gt: the type of generator (see enum GeneratorType in generator.h)
* @param powerState: indicate if generator should be on or off when created
*/
Generator::Generator() {}

Generator::Generator(GeneratorType gt, bool powerState) {
type = gt;
isOn = powerState;

// economicDispatchCost currently uses maxPowerOut
// maxPowerOut and minPowerOut are in MW

// +- 50 MW for generating random power-outs within accurate range based off found data, below 50 is +- 5
// +- 20 for generating costs above 50, below 50 is +- 5
if (gt == CoalFiredSteam) {
fuelCost = 1;
startUpCost = 64;
shutDownCost = 25;
maxPowerOut = 600;
minPowerOut = 150;
startUpCost = rand() % 41 + 44; //base: 64
shutDownCost = rand() % 11 + 20; //base: 25
maxPowerOut = rand() % 101 + 550 ; //base: 600
minPowerOut = rand() % 101 + 100; //base: 150
A = 510;
B = 7.2;
C = 0.00142;
economicDispatchCost = A + B*maxPowerOut + C*pow(maxPowerOut, 2);
} else if (gt == OilFiredSteam){
fuelCost = 1;
startUpCost = 46;
shutDownCost = 15;
maxPowerOut = 400;
minPowerOut = 100;
startUpCost = rand() % 11 + 41; //base: 46;
shutDownCost = rand() % 11 + 10; //base: 15
maxPowerOut = rand() % 101 + 350; //base: 400;
minPowerOut = rand() % 101 + 50; //base: 100;
A = 310;
B = 7.85;
C = 0.00194;
economicDispatchCost = A + B*maxPowerOut + C*pow(maxPowerOut, 2);
} else if (gt == SmallSub) {
fuelCost = 1;
startUpCost = 112;
shutDownCost = 5;
maxPowerOut = 100;
minPowerOut = 20;
startUpCost = rand() % 41 + 92; //base: 112
shutDownCost = rand() % 11 + 1; //base: 6
maxPowerOut = rand() % 101 + 50;//base: 100
minPowerOut = rand() % 11 + 15; //base: 20
A = 80;
B = 8;
C = 0.024;
economicDispatchCost = 0;
} else if (gt == LargeSub) {
fuelCost = 1;
startUpCost = 78;
shutDownCost = 10;
maxPowerOut = 350;
minPowerOut = 45;
startUpCost = rand() % 41 + 58; //base: 78
shutDownCost = rand() % 11 + 5; //base: 10
maxPowerOut = rand() % 101 + 300; //base: 350
minPowerOut = rand() % 11 + 40; //base: 45
A = 225;
B = 8.4;
C = 0.0025;
economicDispatchCost = A + B*maxPowerOut + C*pow(maxPowerOut, 2);
} else if (gt == OtherSteam) {
fuelCost = 1;
startUpCost = 48;
shutDownCost = 20;
maxPowerOut = 200;
minPowerOut = 20;
startUpCost = rand() % 11 + 43; //base: 48
shutDownCost = rand() % 11 + 15; //base: 20
maxPowerOut = rand() % 101 + 150; //base: 200
minPowerOut = rand() % 11 + 15; //base: 20
A = 400;
B = 5;
C = 0.01;
Expand Down
1 change: 1 addition & 0 deletions src/generator.h → src/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Generator {
public:
double sum(int x, int y);
Generator(GeneratorType gt, bool powerState);
Generator();
double getFuelCost() const;
double getStartUpCost() const;
double getShutDownCost() const;
Expand Down
106 changes: 52 additions & 54 deletions src/dijkstra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,68 @@

#include <limits.h>
#include <stdio.h>
#include "dijkstra.h"


// Number of vertices in the graph
#define V 9


// A utility function to find the vertex with minimum distance value, from
// the set of vertices not yet included in shortest path tree
int minDistance(int dist[], bool sptSet[])
{
// Initialize min value
int min = INT_MAX, min_index;
int minDistance(int dist[], bool sptSet[]) {
// Initialize min value
int min = INT_MAX, min_index;

for (int v = 0; v < V; v++)
if (sptSet[v] == false && dist[v] <= min)
min = dist[v], min_index = v;
for (int v = 0; v < V; v++)
if (sptSet[v] == false && dist[v] <= min)
min = dist[v], min_index = v;

return min_index;
}
return min_index;
}

// A utility function to print the constructed distance array
void printSolution(int dist[])
{
printf("Vertex \t\t Distance from Source\n");
for (int i = 0; i < V; i++)
printf("%d \t\t %d\n", i, dist[i]);
}
void printSolution(int dist[]) {
printf("Vertex \t\t Distance from Source\n");
for (int i = 0; i < V; i++)
printf("%d \t\t %d\n", i, dist[i]);
}

// Function that implements Dijkstra's single source shortest path algorithm
// for a graph represented using adjacency matrix representation
void dijkstra(int graph[V][V], int src)
{
int dist[V]; // The output array. dist[i] will hold the shortest
// distance from src to i

bool sptSet[V]; // sptSet[i] will be true if vertex i is included in shortest
// path tree or shortest distance from src to i is finalized

// Initialize all distances as INFINITE and stpSet[] as false
for (int i = 0; i < V; i++)
dist[i] = INT_MAX, sptSet[i] = false;

// Distance of source vertex from itself is always 0
dist[src] = 0;

// Find shortest path for all vertices
for (int count = 0; count < V - 1; count++) {
// Pick the minimum distance vertex from the set of vertices not
// yet processed. u is always equal to src in the first iteration.
int u = minDistance(dist, sptSet);

// Mark the picked vertex as processed
sptSet[u] = true;

// Update dist value of the adjacent vertices of the picked vertex.
for (int v = 0; v < V; v++)

// Update dist[v] only if is not in sptSet, there is an edge from
// u to v, and total weight of path from src to v through u is
// smaller than current value of dist[v]
if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX
&& dist[u] + graph[u][v] < dist[v])
dist[v] = dist[u] + graph[u][v];
void dijkstra(int graph[V][V], int src) {
int dist[V]; // The output array. dist[i] will hold the shortest
// distance from src to i

bool sptSet[V]; // sptSet[i] will be true if vertex i is included in shortest
// path tree or shortest distance from src to i is finalized

// Initialize all distances as INFINITE and stpSet[] as false
for (int i = 0; i < V; i++)
dist[i] = INT_MAX, sptSet[i] = false;

// Distance of source vertex from itself is always 0
dist[src] = 0;

// Find shortest path for all vertices
for (int count = 0; count < V - 1; count++) {
// Pick the minimum distance vertex from the set of vertices not
// yet processed. u is always equal to src in the first iteration.
int u = minDistance(dist, sptSet);

// Mark the picked vertex as processed
sptSet[u] = true;

// Update dist value of the adjacent vertices of the picked vertex.
for (int v = 0; v < V; v++)

// Update dist[v] only if is not in sptSet, there is an edge from
// u to v, and total weight of path from src to v through u is
// smaller than current value of dist[v]
if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX
&& dist[u] + graph[u][v] < dist[v])
dist[v] = dist[u] + graph[u][v];
}

// print the constructed distance array
printSolution(dist);
}

// print the constructed distance array
printSolution(dist);
}

19 changes: 19 additions & 0 deletions src/dijkstra.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Created by Deepson Khadka on 3/23/21.
//

#ifndef CAPSTONE_PROJECT_DIJKSTRA_H
#define CAPSTONE_PROJECT_DIJKSTRA_H
#define V 9

class Dijkstra{
private:

public:
int minDistance(int dist[], bool sptSet[]);
void dijkstra(int graph[V][V], int src);
void printSolution(int dist[]);
};


#endif //CAPSTONE_PROJECT_DIJKSTRA_H
Loading