فهرست منبع

add graph coloring logic

highing666 4 سال پیش
والد
کامیت
f3e5cbf9b0
4فایلهای تغییر یافته به همراه43 افزوده شده و 1 حذف شده
  1. 20 0
      app/api/routers/algorithms.py
  2. 7 0
      app/controllers/algorithms/graph_coloring.py
  3. 2 1
      app/main.py
  4. 14 0
      app/models/domain/algorithms.py

+ 20 - 0
app/api/routers/algorithms.py

@@ -0,0 +1,20 @@
+from fastapi import APIRouter, Query
+
+from app.controllers.algorithms.graph_coloring import get_graph_coloring
+from app.models.domain.algorithms import GraphColoringRequest, GraphColoringResponse
+
+router = APIRouter()
+
+
+@router.post('/graph-coloring', response_model=GraphColoringResponse)
+async def get_graph_coloring_result(graph_info: GraphColoringRequest):
+    black, white, random = await get_graph_coloring(
+        graph_info.vertexes,
+        graph_info.edges
+    )
+
+    return {
+        'black': black,
+        'white': white,
+        'random': random
+    }

+ 7 - 0
app/controllers/algorithms/graph_coloring.py

@@ -0,0 +1,7 @@
+from typing import List, Tuple
+
+from loguru import logger
+
+
+async def get_graph_coloring(vertexes: List[str], edges: List[List[str]]) -> Tuple[List[str], List[str], List[str]]:
+    pass

+ 2 - 1
app/main.py

@@ -7,7 +7,7 @@ import uvicorn
 from fastapi import FastAPI
 from loguru import logger
 
-from app.api.routers import targets, equipment, space, item, user, bluetooth, devices, nlp, positioning
+from app.api.routers import algorithms, targets, equipment, space, item, user, bluetooth, devices, nlp, positioning
 from app.api.routers.model_path import early_start
 from app.core.config import settings
 from app.core.events import create_start_app_handler
@@ -25,6 +25,7 @@ def get_application() -> FastAPI:
 
     application.add_event_handler('startup', create_start_app_handler())
 
+    application.include_router(algorithms.router, prefix='/algo', tags=['Algorithms'])
     application.include_router(bluetooth.router, prefix='/bluetooth', tags=['BLE'])
     application.include_router(devices.router, prefix='/devices', tags=['Devices'])
     application.include_router(early_start.router, prefix='/model-path', tags=['Model Path'])

+ 14 - 0
app/models/domain/algorithms.py

@@ -0,0 +1,14 @@
+from typing import List, Optional
+
+from pydantic import BaseModel
+
+
+class GraphColoringResponse(BaseModel):
+    black: List[str]
+    white: List[str]
+    random: List[str]
+
+
+class GraphColoringRequest(BaseModel):
+    vertexes: List[str]
+    edges: List[List[str]]