Skip to main content
. 2024 Nov 12;24(22):7223. doi: 10.3390/s24227223
Algorithm 1 Water Distribution System Optimization
  •  1:

    Globals: threshold_optimization=0.8, unit_cost=0.5, total_resources=0

  •  2:

    Load Data: Xdf[[base_demand]], ydf[[lps_demand]]

  •  3:

    Train Model and Evaluate:

  •  4:

    X_train,X_test,y_train,y_test train_test_split(X, y, 0.2, 42)

  •  5:

    model LinearRegression().fit(X_train, y_train)

  •  6:

    mae mean_absolute_error(y_test, model.predict(X_test))

  •  7:

    Optimization Process:

  •  8:

    df pd.read_excel(’city_LDandBD.xlsx’, names=[’node_id’, ’base_demand’, ’lps_demand’])

  •  9:

    for index,row in  df.iterrows()  do

  • 10:

    node_idrow[node_id], base_demand,lps_demandrow[[base_demand,lps_demand]]

  • 11:

    resourcesbase_demand×unit_cost

  • 12:

    if lps_demand<base_demand×threshold_optimization then

  • 13:

      print(“Successful optimization at node”, node_id)

  • 14:

      resourcesresources×0.9

  • 15:

    else

  • 16:

      print(“Optimization was not achieved in the node”, node_id)

  • 17:

    end if

  • 18:

    total_resourcestotal_resources+resources

  • 19:

    end for