{"id":18374473,"url":"https://github.com/recruit-tech/codable-model-optimizer","last_synced_at":"2025-08-05T04:24:02.797Z","repository":{"id":38085438,"uuid":"465995295","full_name":"recruit-tech/codable-model-optimizer","owner":"recruit-tech","description":"meta-heuristics solver for easy modeling","archived":false,"fork":false,"pushed_at":"2022-10-17T03:26:10.000Z","size":190,"stargazers_count":31,"open_issues_count":0,"forks_count":3,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-03-17T20:54:04.764Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://codable-model-optimizer.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/recruit-tech.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-04T05:32:44.000Z","updated_at":"2025-02-05T23:48:23.000Z","dependencies_parsed_at":"2022-08-08T23:00:51.911Z","dependency_job_id":null,"html_url":"https://github.com/recruit-tech/codable-model-optimizer","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recruit-tech%2Fcodable-model-optimizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recruit-tech%2Fcodable-model-optimizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recruit-tech%2Fcodable-model-optimizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recruit-tech%2Fcodable-model-optimizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/recruit-tech","download_url":"https://codeload.github.com/recruit-tech/codable-model-optimizer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247539474,"owners_count":20955314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T00:14:46.461Z","updated_at":"2025-04-06T19:32:37.256Z","avatar_url":"https://github.com/recruit-tech.png","language":"Python","readme":".. image:: https://img.shields.io/pypi/v/codableopt.svg\n    :target: https://pypi.python.org/pypi/codableopt\n    \n.. image:: https://readthedocs.org/projects/codable-model-optimizer/badge/?version=latest\n    :target: https://codable-model-optimizer.readthedocs.io/ja/latest/?badge=latest\n    :alt: Documentation Status\n\n\n    \n=========================\ncodable-model-optimizer\n=========================\nOptimization problem meta-heuristics solver for easy modeling.\n\n.. index-start-installation-marker\n\nInstallation\n================\n\nUse pip\n-------\n\n.. code-block:: bash\n\n    $ pip install codableopt\n   \nUse setup.py\n------------\n\n.. code-block:: bash\n\n    # Master branch\n    $ git clone https://github.com/recruit-tech/codable-model-optimizer\n    $ python3 setup.py install\n\n\n\n.. index-end-installation-marker\n\nExample Usage\n=================\n\nSample1\n-------------------\n\n.. index-start-sample1\n\n.. code-block:: python\n\n    import numpy as np\n    from codableopt import *\n\n    # set problem\n    problem = Problem(is_max_problem=True)\n\n    # define variables\n    x = IntVariable(name='x', lower=np.double(0), upper=np.double(5))\n    y = DoubleVariable(name='y', lower=np.double(0.0), upper=None)\n    z = CategoryVariable(name='z', categories=['a', 'b', 'c'])\n\n\n    # define objective function\n    def objective_function(var_x, var_y, var_z, parameters):\n        obj_value = parameters['coef_x'] * var_x + parameters['coef_y'] * var_y\n\n        if var_z == 'a':\n            obj_value += 10.0\n        elif var_z == 'b':\n            obj_value += 8.0\n        else:\n            # var_z == 'c'\n            obj_value -= 3.0\n\n        return obj_value\n\n\n    # set objective function and its arguments\n    problem += Objective(objective=objective_function,\n                         args_map={'var_x': x,\n                                   'var_y': y,\n                                   'var_z': z,\n                                   'parameters': {'coef_x': -3.0, 'coef_y': 4.0}})\n\n    # define constraint\n    problem += 2 * x + 4 * y + 2 * (z == 'a') + 3 * (z == ('b', 'c')) \u003c= 8\n    problem += 2 * x - y + 2 * (z == 'b') \u003e 3\n\n    print(problem)\n\n    solver = OptSolver()\n\n    # generate optimization methods to be used within the solver\n    method = PenaltyAdjustmentMethod(steps=40000)\n\n    answer, is_feasible = solver.solve(problem, method)\n    print(f'answer:{answer}, answer_is_feasible:{is_feasible}')\n\n.. index-end-sample1\n\nSample2\n-------------------\n\n\n.. code-block:: python\n\n    import random\n    from itertools import combinations\n\n    from codableopt import Problem, Objective, CategoryVariable, OptSolver, PenaltyAdjustmentMethod\n\n\n    # define distance generating function\n    def generate_distances(args_place_names):\n        generated_distances = {}\n        for point_to_point in combinations(['start'] + args_place_names, 2):\n            distance_value = random.randint(20, 40)\n            generated_distances[point_to_point] = distance_value\n            generated_distances[tuple(reversed(point_to_point))] = distance_value\n        for x in ['start'] + args_place_names:\n            generated_distances[(x, x)] = 0\n\n        return generated_distances\n\n\n    # generate TSP problem\n    PLACE_NUM = 30\n    destination_names = [f'destination_{no}' for no in range(PLACE_NUM)]\n    place_names = [f'P{no}' for no in range(PLACE_NUM)]\n    distances = generate_distances(place_names)\n    destinations = [CategoryVariable(name=destination_name, categories=place_names)\n                    for destination_name in destination_names]\n\n    # set problem\n    problem = Problem(is_max_problem=False)\n\n\n    # define objective function\n    def calc_distance(var_destinations, para_distances):\n        return sum([para_distances[(x, y)] for x, y in zip(\n            ['start'] + var_destinations, var_destinations + ['start'])])\n\n\n    # set objective function and its arguments\n    problem += Objective(objective=calc_distance,\n                         args_map={'var_destinations': destinations, 'para_distances': distances})\n\n    # define constraint\n    # constraint formula that always reaches all points at least once\n    for place_name in place_names:\n        problem += sum([(destination == place_name) for destination in destinations]) \u003e= 1\n\n    # optimization implementation\n    solver = OptSolver(round_times=4, debug=True, debug_unit_step=1000)\n    method = PenaltyAdjustmentMethod(steps=10000, delta_to_update_penalty_rate=0.9)\n    answer, is_feasible = solver.solve(problem, method, n_jobs=-1)\n\n    print(f'answer_is_feasible:{is_feasible}')\n    root = ['start'] + [answer[root] for root in destination_names] + ['start']\n    print(f'root: {\" -\u003e \".join(root)}')\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frecruit-tech%2Fcodable-model-optimizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frecruit-tech%2Fcodable-model-optimizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frecruit-tech%2Fcodable-model-optimizer/lists"}