@@ -417,47 +417,43 @@ HighsStatus normaliseNames(const HighsLogOptions& log_options,
417417 name_suffix = 0 ;
418418 names.resize (num_name_required);
419419 highsLogUser (log_options, HighsLogType::kWarning ,
420- " %6s names are blank or not present: using "
420+ " %s names are blank or not present: using "
421421 " names with prefix \" %s\" , beginning with suffix %d\n " ,
422- column ? " Column" : " Row" , name_prefix.c_str (), int (name_suffix));
422+ column ? " Column" : " Row " , name_prefix.c_str (), int (name_suffix));
423423 for (HighsInt ix = 0 ; ix < num_name_required; ix++)
424424 names[ix] = name_prefix + std::to_string (name_suffix++);
425425 return HighsStatus::kOk ;
426426 }
427427 names.resize (num_name_required);
428- // Form the hash table to check for duplicates
429- if (!name_hash.name2index .size ()) name_hash.form (names);
430-
428+ HighsInt num_blank = 0 ;
429+ const HighsInt from_name_suffix = name_suffix;
431430 for (HighsInt ix = 0 ; ix < num_name_required; ix++) {
432431 if (HighsInt (names[ix].length ()) == 0 ) {
433432 // Name is blank, so create one
433+ num_blank++;
434434 name_prefix = column ? kHighsUniqueColNamePrefix : kHighsUniquerowNamePrefix ;
435- std::string name = name_prefix + std::to_string (name_suffix++);
436- auto search = name_hash.name2index .find (name);
437- if (search == name_hash.name2index .end ()) {
438- // Name not found in hash, so replace blank name
439- names[ix] = name;
440- // Add name to hash, checking for duplicate
441- const bool duplicate =
442- !name_hash.name2index .emplace (name, ix).second ;
443- assert (!duplicate);
444- assert (names[ix] == name);
445- assert (name_hash.name2index .find (name)->second == ix);
446- } else {
447- name_hash.name2index .clear ();
448- return HighsStatus::kError ;
449- }
450- } else {
451- size_t space_pos = names[ix].find (" " );
452- if (space_pos != std::string::npos) {
453- highsLogUser (log_options, HighsLogType::kError ,
454- " %s %d name \" %s\" contains a space character\n " ,
455- column ? " Column" : " Row" ,
456- int (ix), names[ix].c_str ());
457- return HighsStatus::kError ;
458- }
435+ names[ix] = name_prefix + std::to_string (name_suffix++);
436+ } else if (names[ix].find (" " ) != std::string::npos) {
437+ // Name contains a space, so return error
438+ highsLogUser (log_options, HighsLogType::kError ,
439+ " %s %d name \" %s\" contains a space character\n " ,
440+ column ? " Column" : " Row" ,
441+ int (ix), names[ix].c_str ());
442+ return HighsStatus::kError ;
459443 }
460444 }
445+ // Check for duplicates
446+ if (name_hash.hasDuplicate (names)) {
447+ name_hash.name2index .clear ();
448+ return HighsStatus::kError ;
449+ }
450+ if (num_blank)
451+ highsLogUser (log_options, HighsLogType::kWarning ,
452+ " Replaced %d blank %6s name%s by name%s with prefix \" %s\" , beginning with suffix %d\n " ,
453+ int (num_blank), column ? " column" : " row" ,
454+ num_blank > 1 ? " s" : " " ,
455+ num_blank > 1 ? " s" : " " ,
456+ name_prefix.c_str (), int (from_name_suffix));
461457 return HighsStatus::kOk ;
462458}
463459
0 commit comments