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 added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"C_Cpp.errorSquiggles": "disabled"
}
16 changes: 15 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,18 @@ message( ${CMAKE_CXX_FLAGS} )
foreach( appsourcefile ${APP_SOURCES} )
get_filename_component( demo_name ${appsourcefile} NAME_WE )
add_executable( ${demo_name} ${appsourcefile} )
endforeach( appsourcefile ${APP_SOURCES} )
endforeach( appsourcefile ${APP_SOURCES} )


/**


Assignment Requirements for the Algorithms project.
1. I need to make something that shows a nice DEMO. Demonstration. -> The way I can do this is by doing the following:
1. I can start.
2. I can try to figure out how to properly do dependency management (*Decompress a Directed Acyclic Graph -> DAG RFC. With Autocomplete.)


Dependency Management is likely the future. The reason; (We - I, etc.) say this is because proper surveys' can make OR break a companies routine etc. There's a lot of beauty to be able to be seen within this System.
Systems assignment for COE 379L (P.I. -> Marcus.)
**/
128 changes: 70 additions & 58 deletions include/bellman_ford.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* BELLMAN-FORD ALGORITHM
*
Expand Down Expand Up @@ -39,9 +39,9 @@
* v := uv.destination
* if u.distance + uv.weight < v.distance:
* error "Graph contains a negative-weight cycle"
*
*
* http://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm
*
*
******************************************************************************/

#ifndef ALGO_BELLMAN_FORD_H__
Expand All @@ -59,73 +59,85 @@
// define UNDEFINED previous vertex.
#define UNDEFINED -1

namespace alg {
class BellmanFord {
private:
HashTable<int32_t, int32_t> dist; // hash table for distance.
bool has_neg_cycle; // negative weighted cycle mark.
const Graph & g;
public:
BellmanFord(const Graph & graph):
dist(graph.vertex_count()),g(graph) { }

/**
* Bellman-Ford algorithm
*/
HashTable<int32_t, int32_t> * run(uint32_t source) {
// hash table for previous vertex
HashTable<int32_t, int32_t> * previous = new HashTable<int32_t, int32_t>(g.vertex_count());
// source vertex
dist[source] = 0;

// other vertices
Graph::Adjacent * a;
list_for_each_entry(a, &g.list(), a_node){
if (source != a->v.id) {
dist[a->v.id] = INT_MAX;
}
(*previous)[a->v.id] = UNDEFINED;
namespace alg
{
class BellmanFord
{
private:
HashTable<int32_t, int32_t> dist; // hash table for distance.
bool has_neg_cycle; // negative weighted cycle mark.
const Graph &g;

public:
BellmanFord(const Graph &graph) : dist(graph.vertex_count()), g(graph) {}

/**
* Bellman-Ford algorithm
*/
HashTable<int32_t, int32_t> *run(uint32_t source)
{
// hash table for previous vertex
HashTable<int32_t, int32_t> *previous = new HashTable<int32_t, int32_t>(g.vertex_count());
// source vertex
dist[source] = 0;

// other vertices
Graph::Adjacent *a;
list_for_each_entry(a, &g.list(), a_node)
{
if (source != a->v.id)
{
dist[a->v.id] = INT_MAX;
}
(*previous)[a->v.id] = UNDEFINED;
}

has_neg_cycle = false; // negative cycle mark set to 'false'.
has_neg_cycle = false; // negative cycle mark set to 'false'.

// relax edges repeatedly
Graph::Adjacent * u;
for (uint32_t i=0;i<g.vertex_count()-1;i++) { // loop |V| -1 times
list_for_each_entry(u, &g.list(), a_node){ // for each eage(u,v) in edges
int32_t dist_u = dist[u->v.id];
// relax edges repeatedly
Graph::Adjacent *u;
for (uint32_t i = 0; i < g.vertex_count() - 1; i++)
{ // loop |V| -1 times
list_for_each_entry(u, &g.list(), a_node)
{ // for each eage(u,v) in edges
int32_t dist_u = dist[u->v.id];

Graph::Vertex * v;
list_for_each_entry(v, &u->v_head, v_node){
int32_t dist_v = dist[v->id];
Graph::Vertex *v;
list_for_each_entry(v, &u->v_head, v_node)
{
int32_t dist_v = dist[v->id];

if (dist_u + v->weight < dist_v) {
dist[v->id] = dist_u + v->weight;
(*previous)[v->id] = u->v.id;
}
if (dist_u + v->weight < dist_v)
{
dist[v->id] = dist_u + v->weight;
(*previous)[v->id] = u->v.id;
}
}
}
}

// check for negative-weight cycles
list_for_each_entry(u, &g.list(), a_node) {
int32_t dist_u = dist[u->v.id];
// check for negative-weight cycles
list_for_each_entry(u, &g.list(), a_node)
{
int32_t dist_u = dist[u->v.id];

Graph::Vertex * v;
list_for_each_entry(v, &u->v_head, v_node){
int32_t dist_v = dist[v->id];
Graph::Vertex *v;
list_for_each_entry(v, &u->v_head, v_node)
{
int32_t dist_v = dist[v->id];

if (dist_u + v->weight < dist_v) {
has_neg_cycle = true; // graph contains a negative-weight cycle
return previous;
}
}
if (dist_u + v->weight < dist_v)
{
has_neg_cycle = true; // graph contains a negative-weight cycle
return previous;
}
}

return previous;
}

inline bool has_negative_cycle() { return has_neg_cycle; }
return previous;
}

inline bool has_negative_cycle() { return has_neg_cycle; }
};
}

Expand Down
3 changes: 2 additions & 1 deletion include/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ namespace alg {
* clear the heap
*/
inline void clear() { m_size = 0; }


// @feat? bin search
bool contains(const T & data) {
for(int i=0;i<m_size;i++) {
if(m_heap[i].data== data) return true;
Expand Down
36 changes: 36 additions & 0 deletions include/siddhant's-algorithm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/********************************

What am I trying to do?
-_____ \

|
|
v
Assignment Requirements for the Algorithms project.
1. I need to make something that shows a nice DEMO. Demonstration. -> The way I can do this is by doing the following:
1. I can start.
2. I can try to figure out how to properly do dependency management (*Decompress a Directed Acyclic Graph -> DAG RFC. With Autocomplete.)

Today, I will be making the world's first. (Probably not first)
-> Realtime Dependency manamgment/cross-platform/Nop(Not an Operation.)
*/

#ifndef _SIDDHANT_SINGH___
#include <stdint.h>
#include <stdlib.h>

namespace alg {
/*
M.J. plays in the background. (this is a Micheal Jackson Song.)
*/
template <typename T=(***?***)>
class V {
private:
public:

};
/*T: 00:30:08. pre-Bound2.*/
/*Look At m_hash e data uhash_init S T rand T M S I rand E T namespace I walking I S we wheather if I A qq aaaa A aaaaa aaaaa A -> don't blink.
};

#endif //-> although I don't know magic. I can learn it. (Santa's Little Helper.)
19 changes: 19 additions & 0 deletions msvc/me_v_solver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Dependency Management is likely the future.
|

\
\


|

v


The reason; (We - I, etc.) say this is because proper surveys' can make OR break a companies routine etc. There's a lot of beauty to be able to be seen within this System.
Systems assignment for COE 379L (P.I. -> Marcus.)


*/

Empty file added src/siddhant-singh_demo.cpp
Empty file.