void lmm_print(lmm_system_t sys)
{
- void *_cnst, *_elem, *_var;
+ void* _cnst;
+ void* _elem;
+ void* _var;
lmm_constraint_t cnst = nullptr;
- lmm_element_t elem = nullptr;
- lmm_variable_t var = nullptr;
- xbt_swag_t cnst_list = nullptr;
- xbt_swag_t var_list = nullptr;
- xbt_swag_t elem_list = nullptr;
- xbt_strbuff_t buf = xbt_strbuff_new();
+ lmm_element_t elem = nullptr;
+ lmm_variable_t var = nullptr;
+ xbt_swag_t cnst_list = nullptr;
+ xbt_swag_t var_list = nullptr;
+ xbt_swag_t elem_list = nullptr;
+ std::string buf = std::string("MAX-MIN ( ");
double sum = 0.0;
/* Printing Objective */
var_list = &(sys->variable_set);
- xbt_strbuff_append(buf, "MAX-MIN ( ");
xbt_swag_foreach(_var, var_list) {
var = (lmm_variable_t)_var;
- xbt_strbuff_printf(buf, "'%d'(%f) ", var->id_int, var->weight);
+ buf = buf + "'" + std::to_string(var->id_int) + "'(" + std::to_string(var->weight) + ") ";
}
- xbt_strbuff_append(buf, ")");
- XBT_DEBUG("%20s", buf->data);
- xbt_strbuff_clear(buf);
+ buf += ")";
+ XBT_DEBUG("%20s", buf.c_str());
+ buf.clear();
XBT_DEBUG("Constraints");
/* Printing Constraints */
sum = 0.0;
//Show the enabled variables
elem_list = &(cnst->enabled_element_set);
- xbt_strbuff_append(buf, "\t");
- xbt_strbuff_printf(buf, "%s(", (cnst->sharing_policy)?"":"max");
+ buf += "\t";
+ buf += ((cnst->sharing_policy) ? "(" : "max(");
xbt_swag_foreach(_elem, elem_list) {
elem = (lmm_element_t)_elem;
- xbt_strbuff_printf(buf, "%f.'%d'(%f) %s ", elem->value,
- elem->variable->id_int, elem->variable->value,(cnst->sharing_policy)?"+":",");
+ buf = buf + std::to_string(elem->value) + ".'" + std::to_string(elem->variable->id_int) + "'(" +
+ std::to_string(elem->variable->value) + ")" + ((cnst->sharing_policy) ? " + " : " , ");
if(cnst->sharing_policy)
sum += elem->value * elem->variable->value;
else
elem_list = &(cnst->disabled_element_set);
xbt_swag_foreach(_elem, elem_list) {
elem = (lmm_element_t)_elem;
- xbt_strbuff_printf(buf, "%f.'%d'(%f) %s ", elem->value,
- elem->variable->id_int, elem->variable->value,(cnst->sharing_policy)?"+":",");
+ buf = buf + std::to_string(elem->value) + ".'" + std::to_string(elem->variable->id_int) + "'(" +
+ std::to_string(elem->variable->value) + ")" + ((cnst->sharing_policy) ? " + " : " , ");
if(cnst->sharing_policy)
sum += elem->value * elem->variable->value;
else
sum = MAX(sum,elem->value * elem->variable->value);
}
- xbt_strbuff_printf(buf, "0) <= %f ('%d')", cnst->bound, cnst->id_int);
+ buf = buf + "0) <= " + std::to_string(cnst->bound) + " ('" + std::to_string(cnst->id_int) + "')";
if (!cnst->sharing_policy) {
- xbt_strbuff_printf(buf, " [MAX-Constraint]");
+ buf += " [MAX-Constraint]";
}
- XBT_DEBUG("%s", buf->data);
- xbt_strbuff_clear(buf);
+ XBT_DEBUG("%s", buf.c_str());
+ buf.clear();
xbt_assert(!double_positive(sum - cnst->bound, cnst->bound*sg_maxmin_precision),
"Incorrect value (%f is not smaller than %f): %g", sum, cnst->bound, sum - cnst->bound);
//if(double_positive(sum - cnst->bound, cnst->bound*sg_maxmin_precision))
XBT_DEBUG("'%d'(%f) : %f", var->id_int, var->weight, var->value);
}
}
-
- xbt_strbuff_free(buf);
}
void lmm_solve(lmm_system_t sys)
}
}
+// FIXME: The following duplicates the content of s4u::Host
+namespace simgrid {
+namespace s4u {
+extern std::map<std::string, simgrid::s4u::Host*> host_list;
+}
+}
+
static int surf_parse_models_setup_already_called = 0;
/** The current AS in the parsing */
sg_host_t host = sg_host_by_name(process->host);
if (!host) {
// The requested host does not exist. Do a nice message to the user
- char* tmp = bprintf("Cannot create process '%s': host '%s' does not exist\nExisting hosts: '", process->function,
- process->host);
- xbt_strbuff_t msg = xbt_strbuff_new_from(tmp);
- free(tmp);
- xbt_dynar_t all_hosts = xbt_dynar_sort_strings(sg_hosts_as_dynar());
- simgrid::s4u::Host* host;
- unsigned int cursor;
- xbt_dynar_foreach(all_hosts,cursor, host) {
- xbt_strbuff_append(msg, host->cname());
- xbt_strbuff_append(msg,"', '");
- if (msg->used > 1024) {
- msg->data[msg->used-3]='\0';
- msg->used -= 3;
-
- xbt_strbuff_append(msg," ...(list truncated)......");// That will be shortened by 3 chars when existing the loop
+ std::string msg = std::string("Cannot create process '") + process->function + "': host '" + process->host +
+ "' does not exist\nExisting hosts: '";
+ for (auto kv : simgrid::s4u::host_list) {
+ simgrid::s4u::Host* host = kv.second;
+ msg += host->name();
+ msg += "', '";
+ if (msg.length() > 1024) {
+ msg.pop_back(); // remove trailing quote
+ msg += "...(list truncated)......";
break;
}
}
- msg->data[msg->used-3]='\0';
- xbt_die("%s", msg->data);
+ xbt_die("%s", msg.c_str());
}
simgrid::simix::ActorCodeFactory& factory = SIMIX_get_actor_code_factory(process->function);
xbt_assert(factory, "Function '%s' unknown", process->function);