/** * Ejecuta la metaheurística con los datos dados. * * @param type Si se utilizará una función objetivo de * maximización o de minimización. */ void Kmeans::run(int type){ int i; //////////////////////////// // Inicializaciones. //Inicializaciones del mejor según el tipo de problema. float best; if(initialized){ switch(type){ case T_MAX: //Maximización. best = 0.0; break; default: //Minimización. best = numeric_limits<float>::infinity(); } }else{ best = bestFO; } int count = 0; //////////////////////////// // Algoritmo K-means. while(count < REPS){ ////////////////////////////// // Reasignación y evaluación. //Asignar elementos a cada cluster. for(i = 0; i < N; ++i) solution[0][i] = bestCluster(0, i); //Renombra los clusters y recalcula los centroides. renamer(0, &Ks[0], size); //Evalua la función objetivo. switch(type){ case T_MAX: of[0] = foMax(0, Ks[0], metric); break; default: of[0] = foMin(0, Ks[0], metric); } //////////////////////////// // Actualización del mejor. updateBetter(0, &best, &count, type); } }
void Vxls::renameOperands() { for (auto b : blocks) { auto pos = block_ranges[b].start; pos += 2; // skip implied label for (auto& inst : unit.blocks[b].code) { Renamer renamer(*this, pos); visit(inst, renamer); pos += 2; } } if (dumpIREnabled(kRegAllocLevel)) { print("after renaming operands"); } }
void TCompiler::rewriteCSSShader(TIntermNode* root) { RenameFunction renamer("main(", "css_main("); root->traverse(&renamer); }
void DialogStyleEditor::Apply(bool apply, bool close) { if (apply) { std::string new_name = from_wx(StyleName->GetValue()); // Get list of existing styles std::vector<std::string> styles = store ? store->GetNames() : c->ass->GetStyles(); // Check if style name is unique AssStyle *existing = store ? store->GetStyle(new_name) : c->ass->GetStyle(new_name); if (existing && existing != style) { wxMessageBox(_("There is already a style with this name. Please choose another name."), _("Style name conflict"), wxOK | wxICON_ERROR | wxCENTER); return; } // Style name change bool did_rename = false; if (work->name != new_name) { if (!store && !is_new) { StyleRenamer renamer(c, work->name, new_name); if (renamer.NeedsReplace()) { // See if user wants to update style name through script int answer = wxMessageBox( _("Do you want to change all instances of this style in the script to this new name?"), _("Update script?"), wxYES_NO | wxCANCEL); if (answer == wxCANCEL) return; if (answer == wxYES) { did_rename = true; renamer.Replace(); } } } work->name = new_name; } UpdateWorkStyle(); *style = *work; style->UpdateData(); if (is_new) { if (store) store->push_back(std::unique_ptr<AssStyle>(style)); else c->ass->Styles.push_back(*style); is_new = false; } if (!store) c->ass->Commit(_("style change"), AssFile::COMMIT_STYLES | (did_rename ? AssFile::COMMIT_DIAG_FULL : 0)); // Update preview if (!close) SubsPreview->SetStyle(*style); } if (close) { EndModal(apply); if (PreviewText) OPT_SET("Tool/Style Editor/Preview Text")->SetString(from_wx(PreviewText->GetValue())); } }
bool ConvertLegacyProjectFile(wxFileName filename) { wxTextFile f; XMLFileWriter xmlFile; int index = 0; wxString backupName; do { index++; fflush(stdout); backupName = filename.GetPath() + wxFILE_SEP_PATH + filename.GetName() + wxT("_bak") + wxString::Format(wxT("%d"), index) + wxT(".") + filename.GetExt(); } while(::wxFileExists(backupName)); // This will move the original file out of the way, but // move it back if we exit from this function early. AutoRollbackRenamer renamer(filename.GetFullPath(), backupName); if (!renamer.RenameSucceeded()) return false; f.Open(backupName); if (!f.IsOpened()) return false; wxString name = filename.GetFullPath(); try { xmlFile.Open(name, wxT("wb")); } catch (XMLFileWriterException* pException) { delete pException; return false; } renamer.SetNewFile(xmlFile.fp()); try { xmlFile.Write(wxT("<?xml version=\"1.0\"?>\n")); wxString label; wxString value; if (f.GetFirstLine() != wxT("AudacityProject")) return false; if (f.GetNextLine() != wxT("Version")) return false; if (f.GetNextLine() != wxT("0.95")) return false; if (f.GetNextLine() != wxT("projName")) return false; xmlFile.StartTag(wxT("audacityproject")); xmlFile.WriteAttr(wxT("projname"), f.GetNextLine()); xmlFile.WriteAttr(wxT("version"), wxT("1.1.0")); xmlFile.WriteAttr(wxT("audacityversion"),AUDACITY_VERSION_STRING); label = f.GetNextLine(); while (label != wxT("BeginTracks")) { xmlFile.WriteAttr(label, f.GetNextLine()); label = f.GetNextLine(); } label = f.GetNextLine(); while (label != wxT("EndTracks")) { bool success = ConvertLegacyTrack(&f, xmlFile); if (!success) return false; label = f.GetNextLine(); } xmlFile.EndTag(wxT("audacityproject")); xmlFile.Close(); } catch (XMLFileWriterException* pException) { // Error writing XML file (e.g. disk full) delete pException; return false; } renamer.Finished(); ::wxMessageBox(wxString::Format(_("Converted a 1.0 project file to the new format.\nThe old file has been saved as '%s'"), backupName.c_str()), _("Opening Audacity Project")); return true; }
bool ConvertLegacyProjectFile(wxFileName filename) { wxTextFile f; FILE *outf; int index = 0; wxString backupName; do { index++; fflush(stdout); backupName = filename.GetPath() + wxFILE_SEP_PATH + filename.GetName() + wxT("_bak") + wxString::Format(wxT("%d"), index) + wxT(".") + filename.GetExt(); } while(::wxFileExists(FILENAME(backupName))); // This will move the original file out of the way, but // move it back if we exit from this function early. AutoRollbackRenamer renamer(filename.GetFullPath(), backupName); if (!renamer.RenameSucceeded()) return false; f.Open(FILENAME(backupName)); if (!f.IsOpened()) return false; wxString name = filename.GetFullPath(); wxFFile out_wxFFile(FILENAME(name).c_str(), wxT("wb")); if (!out_wxFFile.IsOpened()) return false; outf = out_wxFFile.fp(); fprintf(outf, "<?xml version='1.0'?>\n"); renamer.SetNewFile(outf); wxString label; wxString value; if (f.GetFirstLine() != wxT("AudacityProject")) return false; if (f.GetNextLine() != wxT("Version")) return false; if (f.GetNextLine() != wxT("0.95")) return false; if (f.GetNextLine() != wxT("projName")) return false; fprintf(outf, "<audacityproject projname='%s'", (const char *)f.GetNextLine().mb_str()); fprintf(outf, " version='1.1.0' audacityversion='%s'", AUDACITY_VERSION_STRING); label = f.GetNextLine(); while (label != wxT("BeginTracks")) { value = f.GetNextLine(); fprintf(outf, " %s='%s'", (const char *)label.mb_str(), (const char *)value.mb_str()); label = f.GetNextLine(); } fprintf(outf, ">\n"); label = f.GetNextLine(); while (label != wxT("EndTracks")) { bool success = ConvertLegacyTrack(&f, outf); if (!success) return false; label = f.GetNextLine(); } fprintf(outf, "</audacityproject>\n"); renamer.Finished(); ::wxMessageBox(wxString::Format(_("Converted a 1.0 project file to the new format.\nThe old file has been saved as '%s'"), backupName.c_str()), _("Opening Audacity Project")); return true; }