Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
Removed unnecessary features
Organisation

Took 8 minutes
  • Loading branch information
flankedgonerogue committed Jan 11, 2024
1 parent a6e833c commit b998f4c
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 114 deletions.
107 changes: 70 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,91 @@
# Mining FIs using CLM

## Interacting with the CPP part
### Possible command-line arguments
```text
-output output.json
-history history.json
-transaction "ABCD FEDC ASIJ LSNQ ISNE"
-image image.json
-min-support 2
-mfis-output mfi.json
```
`-output`: /path/to/output.json - Stores the final image of the graph in this file.

`-history`: /path/to/history.json - Stores the jsonHistory part of the final image of the graph in this file.

`-transactions`: Input transactions to be processed by graph algorithm, separated by whitespaces.

`-image`: /path/to/image.json - Loads up the initial graph from a JSON image.

`-min-support`: minimum support value for MFIs.
### Required command-line arguments
`transactions`: the input transactions
`max-nodes`: the maximum number of nodes in the universe transactions
`min-support`: the minimum support number to find valid FIs

`-mfis-output`: /path/to/mfi.json - Stores MFIs calculated using `min-support` in this file.

If neither `-output` and `-history` are provided then the script pretty-prints final graph image to console.
### Optional command-line arguments
`graph-output`: the JSON file to store graph output in
`fis-output`: the JSON file to store FIs found using `min-support` in
`image`: the initial image JSON file to load the graph from, this should be an instance of JSON using the `output` argument.

### Return codes
```text
0 : Success
1 : Invalid set of arguments
2 : Bad history file
3 : Bad output file
4 : Bad image file
5 : No transactions provided
6 : Failed to open image file
7 : Failed to open history file
8 : Failed to open output file
9 : Bad min support number
10 : Bad mfis output file
11 : Bad max nodes count
12 : Max nodes not specified
2 : Max Nodes number not provided
3 : Max Nodes number is invalid
4 : Min Support number not provided
5 : Min Support number is invalid
6 : Transactions not provided
10 : Bad Graph Output file
11 : Failed to write to Graph Output file
20 : Bad FIs Output file
21 : Failed to write to FIs Output file
30 : Failed to load up image file
```

## Example
A simple run to process the transactions `BCDE ABDE BCDE ABCDE DE C` and store the output to `output.json` and load up the graph from the image file `image.json`.
### Example Run
A simple run to process the transactions `CDEF DE FG CDF DF CEF BCDEF` with a `min support` of 2.

```text
clm-miner.exe -image image.json -output output.json -transactions "BCDE ABDE BCDE ABCDE DE C"
clm-miner -transactions "CDEF DE FG CDF DF CEF BCDEF" -min-support 4 -max-nodes 6
```
Output:
```text
Nodes:
node : weight
B : 1
C : 4
D : 5
E : 4
F : 6
G : 1
Edges:
from : to : extra information : weight
C : D : E,F, : 2
C : E : F, : 3
C : F : : 4
D : E : F, : 2
D : F : : 4
E : F : : 3
D : E : : 1
F : G : : 1
C : D : F, : 1
B : C : D,E,F, : 1
B : D : E,F, : 1
B : E : F, : 1
B : F : : 1
CLM:
| B | B C D E F G | C | B C D E F G | D | B C D E F G | E | B C D E F G | F | B C D E F G | G | B C D E F G |
B | 1 | 0 0 0 0 0 0 | 1 | 0 0 1 1 1 0 | 1 | 0 0 0 1 1 0 | 1 | 0 0 0 0 1 0 | 1 | 0 0 0 0 0 0 | 0 | 0 0 0 0 0 0 |
C | 0 | 0 0 0 0 0 0 | 4 | 0 0 0 0 0 0 | 3 | 0 0 0 2 3 0 | 3 | 0 0 0 0 3 0 | 4 | 0 0 0 0 0 0 | 0 | 0 0 0 0 0 0 |
D | 0 | 0 0 0 0 0 0 | 0 | 0 0 0 0 0 0 | 5 | 0 0 0 0 0 0 | 3 | 0 0 0 0 2 0 | 4 | 0 0 0 0 0 0 | 0 | 0 0 0 0 0 0 |
E | 0 | 0 0 0 0 0 0 | 0 | 0 0 0 0 0 0 | 0 | 0 0 0 0 0 0 | 4 | 0 0 0 0 0 0 | 3 | 0 0 0 0 0 0 | 0 | 0 0 0 0 0 0 |
F | 0 | 0 0 0 0 0 0 | 0 | 0 0 0 0 0 0 | 0 | 0 0 0 0 0 0 | 0 | 0 0 0 0 0 0 | 6 | 0 0 0 0 0 0 | 1 | 0 0 0 0 0 0 |
G | 0 | 0 0 0 0 0 0 | 0 | 0 0 0 0 0 0 | 0 | 0 0 0 0 0 0 | 0 | 0 0 0 0 0 0 | 0 | 0 0 0 0 0 0 | 1 | 0 0 0 0 0 0 |
FIs:
C
CD
CE
CF
D
DE
DF
E
EF
F
Process finished with exit code 0
```
The script returns `code 0` if everything works fine.

## Contributors
```text
- Abdur Rahman Goraya (Graph, Edges, CLM, CLM-Miner, CPP API)
- Syed Ahsan Naqvi (UI)
- Mian Ali Ahmed (CLM-Miner?)
- Mian Ali Ahmed
- Course Instructor: Dr. Zahid Halim
- Course Lab Instructor: Sir Usama Arshad
```
Expand Down
146 changes: 69 additions & 77 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,90 +5,77 @@

int main(int argc, char **argv)
{
// Check if arguments are in pairs
if ((argc - 1) % 2 != 0)
{
std::cout << "An argument is missing!\n";
return 1;
}

// Get all arguments in a map
std::map<std::string, std::string> arguments;
for (int i = 1; i < argc; ++ ++i)
{
arguments[std::string(argv[i])] = std::string(argv[i + 1]);
}

/*
* -history json file to store history in
* -transactions list of input transactions
* -output json file to store final graph output in
*/

if (arguments.contains("-history") && !arguments["-history"].ends_with(".json"))
{
std::cout << "History file must be a json file!\n";
return 2;
}
if (arguments.contains("-output") && !arguments["-output"].ends_with(".json"))
{
std::cout << "Output file must be a json file!\n";
return 3;
}
if (arguments.contains("-image") && !arguments["-image"].ends_with(".json"))
{
std::cout << "Image file must be a json file!\n";
return 4;
}
if (!arguments.contains("-transactions"))
{
std::cout << "No transactions provided!\n";
return 5;
}

int minSupport = -1;
if (arguments.contains("-min-support"))
// Check for valid max nodes
int maxNodes;
if (arguments.contains("-max-nodes"))
{
try
{
minSupport = std::stoi(arguments["-min-support"]);
maxNodes = std::stoi(arguments["-max-nodes"]);

if (minSupport < 1)
if (maxNodes < 1)
{
throw std::exception();
}

} catch (std::exception& _)
{
std::cout << "Min support is not a valid number!\n";
std::cout << "Max nodes is not a valid number!\n";
std::cout << _.what();

return 9;
return 2;
}
} else
{
std::cout << "Max nodes are not provided!\n";
return 3;
}

int maxNodes;
if (arguments.contains("-max-nodes"))
// Check for valid min support
int minSupport;
if (arguments.contains("-min-support"))
{
try
{
maxNodes = std::stoi(arguments["-max-nodes"]);
minSupport = std::stoi(arguments["-min-support"]);

if (maxNodes < 1)
if (minSupport < 1)
{
throw std::exception();
}

} catch (std::exception& _)
{
std::cout << "Max nodes is not a valid number!\n";
std::cout << "Min support is not a valid number!\n";
std::cout << _.what();

return 11;
return 4;
}
} else
{
std::cout << "Max nodes not provided!\n";
return 12;
std::cout << "Min support is not provided!\n";
return 5;
}

// Check for valid transactions
if (!arguments.contains("-transactions"))
{
std::cout << "No transactions provided!\n";
return 6;
}
std::vector<std::string> transactions;
const std::string transactions_str = arguments["-transactions"];
for (size_t offset = 0; offset < transactions_str.length();)
Expand All @@ -108,15 +95,19 @@ int main(int argc, char **argv)
offset = pos + 1;
}

// Create the graph
Graph graph(maxNodes);

// Set up graph from image file if specified
// Set up graph from image file if specified (30 - Failed Image Read)
if (arguments.contains("-image"))
{
std::cout << "Image file specified, setting up graph from image!\n";
std::fstream fstream(arguments["-image"]);
if (!fstream.is_open())
return 6;
{
std::cout << "Failed to read image file!";
return 30;
}
graph = nlohmann::json::parse(fstream).get<Graph>();
graph.setMaxNodes(maxNodes);
}
Expand All @@ -127,59 +118,60 @@ int main(int argc, char **argv)
graph.processTransaction(transaction);
}

// Output history to file
if (arguments.contains("-history"))
// Output to Console if no output files specified
if (!(arguments.contains("-output") && arguments.contains("-fis-output")))
{
std::ofstream fstream(arguments["-history"]);
if (!fstream.is_open())
return 7;
fstream << nlohmann::json(graph)["jsonHistory"];
fstream.flush();
fstream.close();
const auto& FIs = graph.useCLM_Miner(minSupport);
std::cout << graph.toString();

std::cout << "FIs:\n";
for (const auto& FI : FIs)
{
std::cout << '\t' << FI << '\n';
}
}

// Output graph as JSON to file
// Output graph as JSON to JSON file (10 - Bad file, 11 - Failed Output)
if (arguments.contains("-output"))
{
if (!arguments["-output"].ends_with(".json"))
{
std::cout << "Bad graph output file!\n";
return 10;
}

std::ofstream fstream(arguments["-output"]);
if (!fstream.is_open())
return 8;
{
std::cout << "Failed graph output!\n";
return 11;
}

fstream << nlohmann::json(graph);
fstream.flush();
fstream.close();
}

if (minSupport != -1)
// Output FIs to a JSON file (20 - Bad file, 21 - Failed Output)
if (arguments.contains("-fis-output"))
{
if (arguments.contains("-fis-output"))
{
std::ofstream fstream(arguments["-fis-output"]);
if (!fstream.is_open())
return 10;

fstream << nlohmann::json(graph.useCLM_Miner(minSupport));
fstream.flush();
fstream.close();
} else
if (!arguments["-image"].ends_with(".json"))
{
std::cout << "No FIs output file specified\n";
std::cout << "Bad FIs output file!\n";
return 20;
}
}

if (!(arguments.contains("-history") && arguments.contains("-output") && arguments.contains("-fis-output")))
{
const auto& FIs = graph.useCLM_Miner(minSupport);
std::cout << graph.toString();

std::cout << "FIs:\n";
for (const auto& FI : FIs)
std::ofstream fstream(arguments["-fis-output"]);
if (!fstream.is_open())
{
std::cout << '\t' << FI << '\n';
std::cout << "Failed FIs output!\n";
return 21;
}
}


fstream << nlohmann::json(graph.useCLM_Miner(minSupport));
fstream.flush();
fstream.close();
}

return 0;
}

0 comments on commit b998f4c

Please sign in to comment.