From 857e3b2171472a3d6db57944a99f8986aff18b0a Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 9 May 2017 14:04:22 +0200 Subject: [PATCH 1/1] avoid division by 0 in ptask maxmin solve. Fix #165 --- src/surf/fair_bottleneck.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/surf/fair_bottleneck.cpp b/src/surf/fair_bottleneck.cpp index d6c424a8b3..270a399737 100644 --- a/src/surf/fair_bottleneck.cpp +++ b/src/surf/fair_bottleneck.cpp @@ -4,11 +4,12 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "xbt/sysdep.h" -#include "xbt/log.h" #include "maxmin_private.hpp" -#include +#include "xbt/log.h" +#include "xbt/sysdep.h" +#include #include +#include XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_maxmin); #define SHOW_EXPR_G(expr) XBT_DEBUG(#expr " = %g",expr); @@ -113,10 +114,11 @@ void bottleneck_solve(lmm_system_t sys) xbt_swag_foreach_safe(_var, _var_next, var_list) { var = static_cast(_var); - double min_inc = var->cnsts[0].constraint->usage / var->cnsts[0].value; - for (int i = 1; i < var->cnsts_number; i++) { + double min_inc = DBL_MAX; + for (int i = 0; i < var->cnsts_number; i++) { lmm_element_t elm = &var->cnsts[i]; - min_inc = MIN(min_inc, elm->constraint->usage / elm->value); + if (elm->value > 0) + min_inc = MIN(min_inc, elm->constraint->usage / elm->value); } if (var->bound > 0) min_inc = MIN(min_inc, var->bound - var->value); -- 2.20.1