Skip to content

Commit

Permalink
Updated WorstCase
Browse files Browse the repository at this point in the history
  • Loading branch information
vadyushkins committed Feb 25, 2021
1 parent 6fce7f1 commit fc3391d
Showing 1 changed file with 2 additions and 54 deletions.
56 changes: 2 additions & 54 deletions cfpq_data/src/graphs/worst_case_graph.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
from __future__ import annotations

import sys
from argparse import ArgumentParser, Namespace
from pathlib import Path
from typing import Dict, Tuple, Union, Optional

import rdflib
from tqdm import tqdm

from cfpq_data.src.graphs.rdf_graph import RDF
from cfpq_data.src.utils.cmd_parser_interface import ICmdParser
from cfpq_data.src.utils.rdf_helper import write_to_rdf, add_rdf_edge
from cfpq_data.src.utils.utils import add_graph_dir

NUMBER_OF_WORST_CASES = 12


class WorstCase(RDF, ICmdParser):
class WorstCase(RDF):
"""
WorstCase — graphs with two cycles
Expand All @@ -43,7 +40,7 @@ def build(cls,
:rtype:WorstCase
"""

if type(args[0]) is int:
if isinstance(args[0], int):
vertices_number = int(args[0])
path_to_graph = gen_worst_case_graph(add_graph_dir('WorstCase'), vertices_number)
graph = WorstCase.load_from_rdf(path_to_graph)
Expand All @@ -60,55 +57,6 @@ def build(cls,

return graph

@staticmethod
def init_cmd_parser(parser: ArgumentParser) -> None:
"""
Initialize command line parser
:param parser: WorstCase subparser of command line parser
:type parser: ArgumentParser
:return: None
:rtype: None
"""

parser.add_argument(
'-p',
'--preset',
action='store_true',
help='Load preset WorstCase graphs from dataset'
)
parser.add_argument(
'-n',
'--vertices_number',
required=False,
type=int,
help='Number of vertices of WorstCase graph'
)

@staticmethod
def eval_cmd_parser(args: Namespace) -> None:
"""
Evaluate command line parser
:param args: command line arguments
:type args: Namespace
:return: None
:rtype: None
"""

if args.preset is False and args.vertices_number is None:
print("One of -p/--preset, -n/--vertices_number required")
sys.exit()

if args.preset is True:
for n in tqdm(range(2, NUMBER_OF_WORST_CASES), desc='WorstCase graphs generation'):
WorstCase.build(2 ** n).save_metadata()

if args.vertices_number is not None:
graph = WorstCase.build(args.vertices_number)
graph.save_metadata()
print(f'Generated {graph.basename} to {graph.dirname}')


def gen_worst_case_graph(destination_folder: Path, vertices_number: int) -> Path:
"""
Expand Down

0 comments on commit fc3391d

Please sign in to comment.