Esempio n. 1
0
def _parse_command_line_args():
    from argparse import ArgumentParser as AP
    ap = AP(description='Load two files and check if their values are similar')
    ap.add_argument('input1',
                    help='Text file that contains single value series')
    ap.add_argument('input2',
                    help='Text file that contains single value series')
    ap.add_argument('--threshold',
                    type=float,
                    default=1e-2,
                    help='Relative threshold for value comparison')
    return ap.parse_args()
Esempio n. 2
0
 def get_args(self):
     parser = AP(
         description=
         "Collecting the kernel version you input and output all of the dates of commit."
     )
     h = """You should input the version as three parts and separate them with SPACE.
     And if you input 'c' as the end of input, the result will be cumulative."""
     parser.add_argument("-v",
                         "--version",
                         required=True,
                         nargs="+",
                         help=h)
     return parser
Esempio n. 3
0
    def command_build(self):
        '''
        Dv_cli build [-dest target_dir] // <- build specified tb
        '''

        parser = AP()
        parser.add_argument(
            'name',
            metavar='NAME',  #nargs='+',
            help='a name of the object type to instance')
        pargs = parser.parse_args(args=self.subcmd_args)

        dvbuild = dv_build.dv_build()
        dvbuild.command_build(pargs.name)
Esempio n. 4
0
def main():
    
    ap = AP()
    ap.add_argument("--config", help="config file", default="i2ptunnel.json")
    ap.add_argument("--debug", default=False, help="enable debug mode", action="store_const", const=True)
    
    args = ap.parse_args()

    lvl = logging.WARN
    if args.debug:
        lvl = logging.DEBUG
    
    logging.basicConfig(level=lvl, format='%(asctime)s %(levelname)s %(name)s >> %(message)s')
    log = logging.getLogger("pyi2ptunnel.main")
    log.debug('debug on')
    if os.path.exists(args.config):
        cfg = config.Load(args.config)
        log.info('loaded config')

        samaddr = "tcp:127.0.0.1:7657"

        # check config for override
        if "sam" in cfg and "addr" in cfg["sam"]:
            samaddr = cfg["sam"]["addr"]
        
        apptunnel = tunnel.TunnelFactory(api="SAM", apiEndpoint=samaddr)
        tunnels = list()        
        tunnels_config = cfg.get('clients', list())
        for tunnel_cfg in tunnels_config:
            type = tunnel_cfg.get("type")
            tun_name = tunnel_cfg.get("name")
            if type:
                # build tunnel factory
                tun = apptunnel.createClient(type, **tunnel_cfg.get("args", dict()))
                if tun:
                    ep_str = tunnel_cfg.get("listen")
                    if ep_str:
                        # start it up
                        ep = serverFromString(reactor, str(ep_str))
                        ep.listen(tun)
                        log.info("{} will listen on {}".format(tun_name, ep_str))
                    else:
                        log.error("no listen address specified for {}".format(tun_name))
            else:
                log.error("no tunnel type specified for {}".format(tun_name))
        log.info("run reactor")
        reactor.run()
    else:
        log.error("no such file: {}".format(args.config))
Esempio n. 5
0
def options(argv):
    usages = "python3 {} -i file_in -l [length] -o [overlap]".format(argv[0])
    description = "script for splitting sequence into parts with given length and overlap size."
    p = AP(usage=usages, description=description)
    p.add_argument("-i",
                   dest="file_in",
                   metavar="file_in",
                   help="Sequence file in format of txt")
    p.add_argument("-o",
                   dest="overlap",
                   metavar="[int]",
                   help="overlap size.",
                   type=int)
    p.add_argument("-l",
                   dest="length",
                   metavar="[int]",
                   help="sequence length after splitted",
                   type=int)
    p.add_argument(
        "-s",
        dest="start",
        metavar="[left/right]",
        choices=["left", "right"],
        help="Sequence split start from left or right. (default: left)",
        default="left")
    p.add_argument("-t",
                   dest="transform",
                   action="store_true",
                   help="Output sequence in transform. (default: False)",
                   default=False)
    p.add_argument(
        "-w",
        dest="inturn",
        action="store_true",
        help=
        "Output sequence in turn of transformed or not, the first sequence depend on option -t. (default: False)",
        default=False)
    p.add_argument(
        "-r",
        dest="report",
        action="store_true",
        help="print sequence split result on screen. (default: False)",
        default=False)

    if len(argv) == 1:
        p.print_help()
        exit(1)
    return p.parse_args(argv[1:])
Esempio n. 6
0
def main(argv=None):

    argv = (argv or sys.argv)[1:]
    parser = AP()
    parser.add_argument('source',
                        type=str,
                        help='source directory to make the gif with')
    parser.add_argument('output',
                        type=str,
                        help='the desired final output filename')
    parser.set_defaults(func=gifit)
    args = parser.parse_args(argv)
    try:
        args.func(args=args)
    except Exception as e:
        parser.error((str(e)))
Esempio n. 7
0
def main():
    # default mempo usk
    mempo_usk = 'USK@oRy7ltZLJM-w-kcOBdiZS1pAA8P-BxZ3BPiiqkmfk0E,6a1KFG6S-Bwp6E-MplW52iH~Y3La6GigQVQDeMjI6rg,AQACAAE/deb.mempo.org'

    # init argparser
    ap = AP()
    ap.add_argument(
        "--usk",
        default=mempo_usk,
        type=str,
        help="custom freenet address to download from (BE VERY CAREFUL)")
    ap.add_argument("--debug",
                    action="store_const",
                    default=False,
                    const=True,
                    help="enable debug output")
    ap.add_argument("--freenet",
                    default="http://127.0.0.1:8888/",
                    type=str,
                    help="url of freenet proxy")
    ap.add_argument("--revision",
                    required=True,
                    type=int,
                    help="freenet repo revision number")

    # parse args
    args = ap.parse_args()

    # determin log level
    lvl = args.debug and logging.DEBUG or logging.INFO

    # config logging
    logging.basicConfig(
        format="%(created)d -- %(name)s-%(levelname)s: %(message)s")

    # set level of mempo logger
    log = logging.getLogger("mempo")
    log.setLevel(lvl)

    # tell the user stuff
    log.info("\t--> obtaining mempo repository via freenet")
    log.warn("\t!!! This WILL take a long time")
    log.info("\t--> using freenet proxy: {}".format(args.freenet))
    log.info("\t--> using revision: {}".format(args.revision))

    # do it :^3
    get_all(args.usk, args.revision, args.freenet)
Esempio n. 8
0
def main():
    """
    main function for keygen
    """
    argparser = AP()
    argparser.add_argument('--keyfile',
                           type=str,
                           required=True,
                           help='place to put generated keys')
    args = argparser.parse_args()
    secret = SigningKey.generate()
    with open(args.keyfile, 'wb') as wfile:
        wfile.write(b'd1:s64:')
        wfile.write(secret.encode())
        wfile.write(secret.verify_key.encode())
        wfile.write(b'e')
    print("{}.loki".format(base32z(secret.verify_key.encode())))
Esempio n. 9
0
def _parse_command_line_args():
    from argparse import ArgumentParser as AP
    ap = AP(
        description=(
            'Run Initializer and check if the distribution of '
            'the resulting values is desired one')
    )
    ap.add_argument(
        'config', help='YAML file with initializer config and test config'
    )
    ap.add_argument(
        '--output', help='Name of output HDF5 file.'
    )
    ap.add_argument(
        '--key', help='Name of dataset in the output file.', default='input'
    )
    return ap.parse_args()
Esempio n. 10
0
    def create_commom_argparse(self, parser=None):
        if (parser == None):
            parser = AP()

        parser.add_argument(
            '--name',
            '-n',
            metavar=('NAME'),
            action='store',
            dest='name',
            required=True,
            help="provide the name of the verification component")
        parser.add_argument(
            '--kind',
            '-k',
            metavar=('KIND'),
            action='store',
            dest='kind',
            required=True,
            help="provide the kind of the verification component")
        parser.add_argument(
            '--package',
            '-p',
            metavar=('PKG'),
            action='store',
            dest='package',
            required=False,
            help="provide the name of the template else defaults to <name>_pkg"
        )
        parser.add_argument('--parent',
                            '-r',
                            metavar=('PARENT'),
                            action='store',
                            dest='parent',
                            required=False,
                            help="provide the name of the parent class")
        parser.add_argument('--set',
                            '-s',
                            nargs=2,
                            metavar=('KEY', 'VALUE'),
                            action='append',
                            default=[],
                            dest='config',
                            help='Override config KEY with VALUE expression')
        return parser
Esempio n. 11
0
def _parse_command_line_args():
    from argparse import ArgumentParser as AP
    ap = AP(
        description='Feed batch data to layer and save the output to file'
    )
    ap.add_argument(
        'config',
        help='File contains layer and run config.'
    )
    ap.add_argument(
        '--output',
        help='Output data file.'
    )
    ap.add_argument(
        '--debug',
        help='Enable debug log', action='store_true'
    )
    return ap.parse_args()
Esempio n. 12
0
    def __init__(self):
        self.project = dv_project.dv_project()
        parser = AP(description=
                    "Top level command for building Verification Environments",
                    usage=sys.argv[0] + ''' <command> [<args>]
        build_agent  - Build a drive uvm component
        build_test   - Build a test component''')
        parser.add_argument('command', help="sub-command to run")
        args = parser.parse_args(sys.argv[1:2])
        self.subcmd_args = sys.argv[2:]

        if not hasattr(self, 'command_' + args.command):
            print("Unknown command")
            parser.print_help()
            exit(1)

        # dispatch to the sub-command
        getattr(self, 'command_' + args.command)()
Esempio n. 13
0
def build():
    prs = AP()
    prs.add_argument('-group',
                     type=str,
                     default=[],
                     nargs="+",
                     action="append",
                     required=True,
                     help="Filenames defining monster groups to fight")
    prs.add_argument(
        '-seed',
        type=int,
        default=None,
        help="Set global RNG seed (default not set--psuedorandom)")
    prs.add_argument('-max-turns',
                     type=int,
                     default=None,
                     help="Limit turns in each brawl (default None)")
    return prs
Esempio n. 14
0
def main():
    p = AP()
    p.add_argument('-o', required=True)
    p.add_argument('--rebuild', action='store_true')
    p.add_argument('--lang', default='es')
    p.add_argument('--country', default='MX')
    p.add_argument('--search_terms',
                   nargs='+',
                   default=[
                       'covid', 'coronavirus', 'pandemia', 'cubrebocas',
                       'tapabocas', 'cuarentena', 'distanciamiento social',
                       'Quédate en Casa', 'sars cov-2'
                   ])
    p.add_argument('--test', action='store_true')
    args = p.parse_args()

    os.makedirs(args.o, exist_ok=True)

    n_days = (NOW - START).days
    if args.test:
        n_days = 5
    days_iter = np.random.permutation(n_days)

    api = API(args.search_terms, args.lang, args.country)

    def worker(day):
        out_path = f'{args.o}/{day}.txt'
        if not args.rebuild:
            if os.path.exists(out_path):
                return
        from_ = START + (day * DAY)
        to_ = from_ + DAY
        from_ = from_.strftime('%Y-%m-%d')
        to_ = to_.strftime('%Y-%m-%d')

        results = api(from_, to_)
        with open(out_path, 'w') as fjson:
            fjson.write('\n'.join(json.dumps(r) for r in results))

    Parallel(n_jobs=8, verbose=10,
             prefer='threads')(delayed(worker)(day) for day in days_iter)
Esempio n. 15
0
def load_env():
    """ define interface and load any environment variables required """
    parser = AP()
    parser.add_argument('--train', nargs='+', required=True, help='Path to training data')
    parser.add_argument('--train_desc', required=True , help='Describe the training data set')
    parser.add_argument('--test', nargs='*', help='Path to test data. Must be omitted or '+\
            'same number of tool files as as --train (and in the same order)')
    parser.add_argument('--test_desc', help='Describe the test data set')
    parser.add_argument('--tool_names', nargs='+', required=True, help='Names of each tool in the same order '+\
            'as given for --train (and --test if provided)')
    parser.add_argument('--trunc_max', nargs='*', type=float,
            help='Truncate maximum values. Must match order of training data')
    parser.add_argument('--trunc_min', nargs='*', type=float,
            help='Truncate minimum values. Must match order of training data')
    parser.add_argument('--debug', action='store_true', help='Turn on debugging output (STDERR)')
    parser.add_argument('--inc_pred', action='store_true', help='Include tool prediction categories '+\
            'in regression. NOTE: must be present in all input files')
    parser.add_argument('--filter', type=float, default=-1, help='Percentage of total reads to remove '+\
            'around mean score, default -1 (disabled)')
    parser.add_argument('--testIsTraining', action='store_true',
            help='Use functions for handling training data for the test parameters')
    parser.add_argument('--no_scaling', action='store_true', help='Disable score scaling')
    args = parser.parse_args()
    # check that the number of command line arguments make sense
    if len(args.train) != len(args.tool_names):
        print('Tool names must match training files', file=sys.stderr)
        sys.exit(-1)
    if args.test and len(args.test) != len(args.train):
        print('Test files must match training files', file=sys.stderr)
        sys.exit(-1)
    if args.test and not args.test_desc:
        print('Description of test data set required', file=sys.stderr)
        sys.exit(-1)
    if args.trunc_max and len(args.trunc_max) != len(args.train):
        print('Truncation maximum values must match against each training input', file=sys.stderr)
        sys.exit(-1)
    if args.trunc_min and len(args.trunc_min) != len(args.train):
        print('Truncation minimum values must match against each training input', file=sys.stderr)
        sys.exit(-1)
    return args
Esempio n. 16
0
def main():
    from argparse import ArgumentParser as AP

    parser = AP(
        description=
        'Mini python script to replace specified value in PCAP(or any binary) file.'
    )
    parser.add_argument('-s',
                        '--srcpcap',
                        help='Path to the raw PCAP file to be anonymized.',
                        required=True)
    parser.add_argument('-d',
                        '--dstpcap',
                        help='Filename of the anonymized PCAP file.',
                        default='anonymized.pcap')
    parser.add_argument(
        '-v',
        '--strvals',
        help='A pair of values before/after anonymized in STRING format.',
        metavar='STRVAL',
        nargs=2,
        action='append')
    parser.add_argument(
        '-x',
        '--hexvals',
        help='A pair of values before/after anonymized in HEX format.',
        metavar='HEXVAL',
        nargs=2,
        action='append')
    args = parser.parse_args()

    validate_args(args.strvals, args.hexvals)

    p = PcapHandler(args.srcpcap, args.dstpcap)
    if args.strvals is not None:
        r = p.replace_strval(args.strvals)
    if args.hexvals is not None:
        r = p.replace_hexval(args.hexvals)
    p.write_pcap(r)
Esempio n. 17
0
    def create_connect_argparse(self, parser=None):
        '''
            inst foo --in bar [-as foo_inst] [-parameter myparm myparmvalue]
        '''
        if (parser == None):
            parser = AP()

        parser.add_argument(
            'name',
            metavar='NAME',  #nargs='+',
            help='a name of the object type to instance')

        parser.add_argument(
            '--in',
            '-i',
            metavar=('INST_LOCATION'),
            action='store',
            dest='inst_loc',
            required=True,
            help="provide the name of the class to place the instance")
        parser.add_argument('--as',
                            '-a',
                            metavar=('INST_NAME'),
                            action='store',
                            dest='inst_name',
                            required=True,
                            help="provide the name of the instance")
        parser.add_argument(
            '--num',
            '-n',
            metavar=('NUM'),
            action='store',
            dest='inst_num',
            required=False,
            help=
            "provide the number of instance as an integer 'q' for a queue or 'd' for dynamic array"
        )

        return parser
Esempio n. 18
0
def _parse_command_line_args():
    from argparse import ArgumentParser as AP
    ap = AP(
        description=('Create sample batch from MNIST dataset. '
                     '(http://deeplearning.net/data/mnist/mnist.pkl.gz) '
                     'Resulting batch has shape (N=10, C[=4], H[=28], W[=27])'
                     'where the first index corresponds to digit.'))
    ap.add_argument('output', help='Output file path')
    ap.add_argument('--input',
                    help='mnist.pkl data',
                    default=os.path.join('data', 'mnist.pkl.gz'))
    ap.add_argument('--key', default='input', help='Name of dataset to create')
    ap.add_argument('--height', default=28, type=int, help='batch height.')
    ap.add_argument('--width', default=27, type=int, help='batch width.')
    ap.add_argument('--channel',
                    default=4,
                    type=int,
                    help='#Channels in batch.')
    ap.add_argument('--plot',
                    action='store_true',
                    help='Visualize the resulting data')
    return ap.parse_args()
Esempio n. 19
0
def _parse_command_line_args():
    from argparse import ArgumentParser as AP
    ap = AP(
        description=('Given a set of DQN parameters, evaluate the performace'))
    ap.add_argument('env', help='Environment configuration file')
    ap.add_argument('agent', help='Agent configuration file')
    ap.add_argument('input_dir',
                    help='Directory where trained parameters are stored')
    ap.add_argument('output_dir',
                    help='Directory where evaluation result is written')
    ap.add_argument('--prefix',
                    default='DQN',
                    help='Prefix of trained parameter files')
    ap.add_argument('--timelimit',
                    type=float,
                    default=300,
                    help='Time limit of one episode')
    ap.add_argument('--episodes',
                    type=int,
                    default=30,
                    help='#Episodes to run')
    return ap.parse_args()
Esempio n. 20
0
def main():
    parser = AP()
    parser.add_argument("-i",
                        "--inputdir",
                        dest="inputdir",
                        help="InputDirectory",
                        required=True)
    parser.add_argument("-s",
                        "--searchstring",
                        dest="searchstring",
                        help="Search String",
                        required=True)
    parser.add_argument("-o",
                        "--outputdir",
                        dest="outputdir",
                        help="JSON Output Dir + Name",
                        required=True)
    if len(sys.argv) < 3:
        parser.print_help()
        sys.exit(1)
    args = parser.parse_args()
    new = searchthis(args.inputdir, args.searchstring)
    with open(args.outputdir, 'w') as outfile:
        json.dump(new, outfile)
Esempio n. 21
0
def parse_args(argv):
    """
    Command line parser

    Parameters
    ----------
    argv : list of strings
        list to parsed

    Returns
    -------
    namespace:
         Parsed arguments
    """

    p = AP(formatter_class=AHF)

    p.add_argument('--cores', '-c', type=int, default=1,
                   help='Number of cores for multiprocessing')
    p.add_argument('--debug', '-d', action="store_true",
                   help='Keep pylauncher workdir after completion')
    p.add_argument('cmdfile', type=str, help="""Input commands file""")

    return p.parse_args(args=argv)
Esempio n. 22
0
def option(argv):
    from argparse import ArgumentParser as AP
    usages = "python3 {} -f fa -i prefix -o outputdir".format(argv[0])
    p = AP(usage=usages)
    p.add_argument("-f",
                   dest="fa",
                   metavar="[fa]",
                   help="fasta file.",
                   required=True)
    p.add_argument("-i",
                   dest="prefix",
                   metavar="[prefix]",
                   help="prefix of *.NC.cluster",
                   required=True)
    p.add_argument("-o",
                   dest="out",
                   metavar="[outputdir]",
                   help="outputdir path",
                   required=True)

    if len(argv) == 1:
        p.print_help()
        exit(1)
    return p.parse_args(argv[1:])
Esempio n. 23
0
def reset_original_mac(interface=None):
    if interface is None:
        print('No interface were provided')
        print_interfaces()
        exit(1)

    check_interface(interface)
    origin_mac = check_output(['ethtool', '-P',
                               interface]).decode().split()[-1]
    change_mac(origin_mac, interface)


check_sudo()

parser = AP()

parser.add_argument('-i',
                    '--interface',
                    dest='interface',
                    default=None,
                    help='select an interface to change the mac address')
parser.add_argument(
    '-m',
    '--mac',
    dest='mac',
    default=rand_mac(),
    help=
    'specify a new mac to change. If not mac address were supply a random mac address will be generated'
)
parser.add_argument(
Esempio n. 24
0
def main():
    ap = AP()
    ap.add_argument('--dir', type=str, default='testnet_tmp')
    ap.add_argument('--svc', type=int, default=20,
                    help='number of service nodes')
    ap.add_argument('--baseport', type=int, default=19000)
    ap.add_argument('--clients', type=int, default=200,
                    help='number of client nodes')
    ap.add_argument('--bin', type=str, required=True)
    ap.add_argument('--out', type=str, required=True)
    ap.add_argument('--connect', type=int, default=10)

    args = ap.parse_args()

    basedir = os.path.abspath(args.dir)

    for nodeid in range(args.svc):
        config = CP()
        config['bind'] = {
            'lo': str(args.baseport + nodeid)
        }
        config['netdb'] = {
            'dir': 'netdb'
        }
        config['connect'] = {}
        for otherid in range(args.svc):
            if otherid != nodeid:
                name = svcNodeName(otherid)
                config['connect'][name] = os.path.join(
                    basedir, name, 'rc.signed')

        d = os.path.join(args.dir, svcNodeName(nodeid))
        if not os.path.exists(d):
            os.mkdir(d)
        fp = os.path.join(d, 'daemon.ini')
        with open(fp, 'w') as f:
            config.write(f)

    for nodeid in range(args.clients):
        config = CP()
        config['netdb'] = {
            'dir': 'netdb'
        }
        config['connect'] = {}
        for otherid in range(args.connect):
            otherid = (nodeid + otherid) % args.svc
            name = svcNodeName(otherid)
            config['connect'][name] = os.path.join(
                basedir, name, 'rc.signed')

        d = os.path.join(args.dir, clientNodeName(nodeid))
        if not os.path.exists(d):
            os.mkdir(d)
        fp = os.path.join(d, 'daemon.ini')
        with open(fp, 'w') as f:
            config.write(f)

    with open(args.out, 'w') as f:
        f.write('''[program:svc-node]
directory = {}
command = {}
redirect_stderr=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
process_name = svc-node-%(process_num)03d
numprocs = {}
'''.format(os.path.join(args.dir, 'svc-node-%(process_num)03d'), args.bin, args.svc))
        f.write('''[program:client-node]
directory = {}
command = {}
redirect_stderr=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
process_name = client-node-%(process_num)03d
numprocs = {}
'''.format(os.path.join(args.dir, 'client-node-%(process_num)03d'), args.bin, args.clients))
        f.write('[supervisord]\ndirectory=.\n')
Esempio n. 25
0
def parse_command_line_arguments():
    from argparse import ArgumentParser as AP
    ap = AP()
    ap.add_argument('input_file', help='fcs file')
    return ap.parse_args()
Esempio n. 26
0
def readFile(filename):
    try:
        file = open(filename)
    except IOError as e:
        sys.stderr.write(str(e) + "\n")
        sys.stderr.write("Try 'touch " + filename + "'\n")
        exit(1)
    else:
        try:
            return json.load(file)
        except:
            return []


if __name__ == "__main__":
    parser = AP(description="Task/Todo List Manager")
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument("--list",
                       help="List all task items",
                       action="store_true")
    group.add_argument("--add",
                       help="Add an item",
                       type=str,
                       dest="newItem",
                       metavar="DESC")
    group.add_argument("--del",
                       help="Delete an item",
                       type=int,
                       dest="delItem",
                       metavar="NUM")
    group.add_argument("--done",
Esempio n. 27
0
    "Boolean function for determing file as binary or hex"
    textchars = bytearray({7, 8, 9, 10, 12, 13, 27}
                          | set(range(0x20, 0x100)) - {0x7F})
    return bool(bytes.translate(None, textchars))


# Regex
patt = r"(?<!\b)CAFE"
subs = "\\nCAFE"

# Parser
parser = AP(
    prog="tube_buffer_clean",
    description="""
        Script to attempt to clean a tube data dump, if corrupt.

        This script only adds newlines in front of any CAFE
        instances that are not at the beginning of a line.
        """,
)
parser.add_argument("file",
                    metavar="file",
                    help="HEX or binary file to be cleaned")
args = parser.parse_args()

with open(args.file, "rb") as file:
    if is_binary(file.read(1024)):
        file.seek(0)
        hexData = file.read().hex().upper()
        outFile = file.name[:-3] + "hex_cleaned"
    else:
Esempio n. 28
0
#!/usr/bin/env python

from argparse import ArgumentParser as AP

parser = AP(description="Perform django commands in a reusable app")
parser.add_argument("action",
                    help="command (e.g. 'makemigrations', 'shell', 'test')")
args = parser.parse_args()

# https://stackoverflow.com/questions/30656162/migrations-in-stand-alone-django-app#answer-32379263
import sys
import django

from django.conf import settings
from django.core.management import call_command

settings.configure(
    DEBUG=True,
    INSTALLED_APPS=(
        'django.contrib.contenttypes',
        'django.contrib.auth',
        'wk',
    ),
    ROOT_URLCONF="urls",
)
#endsnippet

if args.action == "test":
    # 'test' action requires the default database configured
    # Use in-memory sqlite3
    import os
Esempio n. 29
0

def give_init(function_name):
    if function_name == 'B1':
        return np.array([-20, 10])
    elif function_name == 'B2':
        return np.array([10, -10])
    elif function_name == 'B3':
        return np.array([-10, 10])
    elif function_name == 'BL':
        return np.array([1, 2])
    elif function_name == 'RB':
        return np.array([-2.1, 2.1])


p = AP()
p.add_argument(
    '--optim',
    required=True,
    help='Optimizers: GD | CM | Adam | Adagrad | Adadelta | RMSprop')
p.add_argument('--fn',
               required=True,
               help='Function name: B1 | B2 | B3 | BL | RB')
p.add_argument('--iter',
               default=1000,
               type=int,
               help='Number of iterations to run for')
p = p.parse_args()

newDir = os.path.join(p.fn, p.optim)
try:
Esempio n. 30
0
        for inter in n_cars_intert:
            streets = set(self.intersections[inter]['in'])
            streets = list(streets.intersection(set(n_cars_street)))
            random.shuffle(streets)
            self.lights[inter]['streets'] = streets

            ncs = [n_cars_street[s] for s in streets]
            m = max(ncs)
            f = math.ceil
            ncs = [f(max_light_duration*(n/m)) for n in ncs]

            self.lights[inter]['durations'] = ncs

        self.lights = {k:v for k, v in self.lights.items() if len(v['streets']) > 0}

        #print(self.lights)

if __name__ == '__main__':
    parser = AP(description='solveproblem')
    parser.add_argument('-l', dest="max_light_duration", type=float, default=1, help='max duration of a light')
    parser.add_argument('-p', dest="problem", default='a,b,c,d,e,f', help='problem a,b,c,d,e,f')
    args = parser.parse_args()
    probs = args.problem.split(',')

    for p in probs:
        print(f'solving {p}')
        s = Solver(p)
        s.solve(args.max_light_duration)
        s.write_result()
    print('Done')