void Scheduler::run() { _running = true; AbstractTask* task; while (!cyclic() && (!empty() || waiting()) && !_throwing) { if (!empty()) { task = top()._task; *(task->_context) = std::get<0>((*(task->_context))(task)); } checkFutures(); } if (cyclic()) { throw Cycle(cycle()); } if (_throwing) { std::rethrow_exception(_throwing); } _running = false; }
KeyFace::KeyFace(VAC * vac, XmlStreamReader & xml) : Cell(vac, xml), KeyCell(vac, xml), FaceCell(vac, xml) { // Cycles QString str; QStringRef d = xml.attributes().value("cycles"); bool opened = false; for(int i=0; i<d.length(); ++i) { QChar c = d.at(i); if(c == '[') opened = true; if(opened) str += c; if(c==']') { cycles_ << Cycle(); cycles_.last().fromString(str); opened = false; str.clear(); } } }
const double HexagonView::Hue() const { if(m_model) { const double hueDiff = m_hueRange * sin(m_model->GetTime() * m_hueSpeed); const double hue = m_baseHue + hueDiff; return Cycle(hue, 0, 1); } else { return m_baseHue; } }
void CypherScreenInterface::Update () { if ( EclGetAccurateTime () > lastupdate + 75 ) { Cycle (); lastupdate = (int)EclGetAccurateTime (); } }
void Game::Cycle(){ char c; while (!_kbhit()) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0); drawCell(FrameA); update(FrameA, FrameB); Sleep(200); } _getch(); c = _getch(); if (c == 'e') return; for (int i = 0; i < 40; i++) FrameA[rand() % 25][rand() % 80] = FrameB[rand() % 25][rand() % 80] = 1; Cycle(); }
//满足Lenth=3^k-1的perfect shfulle的实现 void Perfect1(int Data[],int Lenth) { int i=1; if(Lenth==2) { i=Data[Lenth-1]; Data[Lenth-1]=Data[Lenth-2]; Data[Lenth-2]=i; return; } while(i<Lenth) { //print(Data,Lenth); Cycle(Data,Lenth,i); i=i*3; } }
void Kruskal(void) { int edge = 0; int ex; while (edge < V - 1) { ex = SelectEdge(); if (!Cycle(ex)) { AddEdge(ex); edge++; PrintST(ex); } else { E[ex].selected = 2; } } cout << "Totol Cost is : " << TotalCost << "\n"; }
LLDependenciesBase::VertexList LLDependenciesBase::topo_sort(int vertices, const EdgeList& edges) const { // Construct a Boost Graph Library graph according to the constraints // we've collected. It seems as though we ought to be able to capture // the uniqueness of vertex keys using a setS of vertices with a // string property -- but I don't yet understand adjacency_list well // enough to get there. All the examples I've seen so far use integers // for vertices. // Define the Graph type. Use a vector for vertices so we can use the // default topological_sort vertex lookup by int index. Use a set for // edges because the same dependency may be stated twice: Node "a" may // specify that it must precede "b", while "b" may also state that it // must follow "a". typedef boost::adjacency_list<boost::setS, boost::vecS, boost::directedS, boost::no_property> Graph; // Instantiate the graph. Without vertex properties, we need say no // more about vertices than the total number. Graph g(edges.begin(), edges.end(), vertices); // topo sort typedef boost::graph_traits<Graph>::vertex_descriptor VertexDesc; typedef std::vector<VertexDesc> SortedList; SortedList sorted; // note that it throws not_a_dag if it finds a cycle try { boost::topological_sort(g, std::back_inserter(sorted)); } catch (const boost::not_a_dag& e) { // translate to the exception we define std::ostringstream out; out << "LLDependencies cycle: " << e.what() << '\n'; // Omit independent nodes: display only those that might contribute to // the cycle. describe(out, false); throw Cycle(out.str()); } // A peculiarity of boost::topological_sort() is that it emits results in // REVERSE topological order: to get the result you want, you must // traverse the SortedList using reverse iterators. return VertexList(sorted.rbegin(), sorted.rend()); }
Object *CreatePrefs(struct Toolbar_DataP *data) { Object **objs = data->Gadgets; Object *textgroup, *imagegroup; Object *prefsgroup; static STRPTR LookStrings[4]; static STRPTR BorderTypeStrings[4]; static STRPTR SelectionModeStrings[4]; static STRPTR PrecisionStrings[5]; static STRPTR GhostEffectStrings[5]; BorderTypeStrings[0] = LOCALE(MSG_BORDERTYPE_OLD, "Old"); BorderTypeStrings[1] = LOCALE(MSG_BORDERTYPE_OFF, "Off"); BorderTypeStrings[2] = LOCALE(MSG_BORDERTYPE_NEW, "New"); BorderTypeStrings[3] = NULL; SelectionModeStrings[0] = LOCALE(MSG_SELECTIONMODE_OLD, "Old"); SelectionModeStrings[1] = LOCALE(MSG_SELECTIONMODE_OFF, "Off"); SelectionModeStrings[2] = LOCALE(MSG_SELECTIONMODE_NEW, "New"); SelectionModeStrings[3] = NULL; LookStrings[0] = LOCALE(MSG_IMAGETEXT, "Image and Text"); LookStrings[1] = LOCALE(MSG_IMAGEONLY, "Image only"); LookStrings[2] = LOCALE(MSG_TEXTONLY, "Text only"); LookStrings[3] = NULL; PrecisionStrings[0] = LOCALE(MSG_EXACT, "Exact"); PrecisionStrings[1] = LOCALE(MSG_IMAGE, "Image"); PrecisionStrings[2] = LOCALE(MSG_ICON, "Icon"); PrecisionStrings[3] = LOCALE(MSG_GUI, "GUI"); PrecisionStrings[4] = NULL; // GhostEffectStrings[0] = LOCALE(MSG_DIMMMED, "Dimmed"); // Temporarily disabled - remember +-1 GhostEffectStrings[0] = LOCALE(MSG_LIGHT, "Light Grid"); GhostEffectStrings[1] = LOCALE(MSG_HEAVY, "Heavy Grid"); GhostEffectStrings[2] = LOCALE(MSG_SUPERLIGHT, "Superlight Grid"); GhostEffectStrings[3] = NULL; prefsgroup = VGroup, Child, VGroup, Child, HGroup, // MUIA_Group_SameWidth, TRUE, /********************************* General *********************************/ Child, HGroup, MUIA_Background, MUII_GroupBack, MUIA_Frame , MUIV_Frame_Group, MUIA_FrameTitle, LOCALE(MSG_GENERAL, "General"), Child, RectangleObject, End, Child, VGroup, Child, RectangleObject, End, Child, objs[Look] = RadioObject, // MUIA_FrameTitle, "Toolbar look", MUIA_Radio_Entries, LookStrings, End, Child, RectangleObject, End, End, //ghosttype Child, RectangleObject, End, End, /********************************* Image *********************************/ Child, imagegroup = HGroup, MUIA_Background, MUII_GroupBack, MUIA_Frame , MUIV_Frame_Group, MUIA_FrameTitle, LOCALE(MSG_IMAGE, "Image"), Child, RectangleObject, End, Child, VGroup, Child, RectangleObject, End, Child, HGroup, Child, RectangleObject, End, Child, VGroup, Child, Label(LOCALE(MSG_USEIMAGES1, "\33cUse ghosted/selected images")), // Child, MUI_MakeObject(MUIO_Label, LOCALE(MSG_USEIMAGES2, "\33c(if they are available)"), MUIO_Label_Tiny), Child, TextObject, MUIA_Text_Contents, LOCALE(MSG_USEIMAGES2, "\33c(if they are available)"), MUIA_Font, MUIV_Font_Tiny, End, End, Child, objs[UseImages] = CheckMark(TRUE), // Child, RectangleObject, End, End, Child, ColGroup(2), // Child, HGroup, Child, Label(LOCALE(MSG_REMAP, "Remap Precision")), Child, objs[Precision] = Cycle(PrecisionStrings), // End, // Child, HGroup, Child, Label(LOCALE(MSG_GHOSTEFFECT, "Ghosting effect")), Child, objs[GhostEffect] = Cycle(GhostEffectStrings), // End, End, Child, RectangleObject, End, End, Child, RectangleObject, End, End, End, /********************************* Spacing *********************************/ Child, HGroup, Child, HGroup, MUIA_Background, MUII_GroupBack, MUIA_Frame , MUIV_Frame_Group, MUIA_FrameTitle, LOCALE(MSG_SPACING, "Spacing"), Child, VGroup, Child, RectangleObject, End, Child, ColGroup(2), Child, Label(LOCALE(MSG_GROUPSPACE, "Group Space")), Child, objs[GroupSpace] = SliderObject, MUIA_Slider_Min, -1, MUIA_Slider_Max, 50, End, Child, Label(LOCALE(MSG_TOOLSPACE, "Tool Space")), Child, objs[ToolSpace] = SliderObject, MUIA_Slider_Min, -1, MUIA_Slider_Max, 10, End, Child, VGroup, Child, Label(LOCALE(MSG_INNERSPACE, "\33cInner Space")), // Child, MUI_MakeObject(MUIO_Label,LOCALE(MSG_INNERSPACE_WITH, "\33c(with tooltext)"), MUIO_Label_Tiny), Child, TextObject, MUIA_Text_Contents, LOCALE(MSG_INNERSPACE_WITH, "\33c(with tooltext)"), MUIA_Font, MUIV_Font_Tiny, End, End, Child, objs[InnerSpace_Text] = SliderObject, MUIA_Slider_Min, 0, MUIA_Slider_Max, 10, End, Child, VGroup, Child, Label(LOCALE(MSG_INNERSPACE, "\33cInner Space")), // Child, MUI_MakeObject(MUIO_Label,LOCALE(MSG_INNERSPACE_WITHOUT, "\33c(without tooltext)"), MUIO_Label_Tiny), Child, TextObject, MUIA_Text_Contents, LOCALE(MSG_INNERSPACE_WITHOUT, "\33c(without tooltext)"), MUIA_Font, MUIV_Font_Tiny, End, End, Child, objs[InnerSpace_NoText] = SliderObject, MUIA_Slider_Min, 0, MUIA_Slider_Max, 10, MUIA_Disabled, TRUE, End, // some kind of relative mode // width: fixed/floating End, Child, RectangleObject, End, End, End, /********************************* Text *********************************/ Child, textgroup = HGroup, MUIA_Background, MUII_GroupBack, MUIA_Frame , MUIV_Frame_Group, MUIA_FrameTitle, LOCALE(MSG_TEXT, "Text"), Child, VGroup, Child, RectangleObject, End, /* Child, HGroup, Child, RectangleObject, End, Child, Label(LOCALE(MSG_PLACEMENT, "Placement")), Child, data->CY_Placement = Cycle(CY_textplacement), // Child, RectangleObject, End, End, */ Child, ColGroup(2), // Child, VGroup, Child, Label(LOCALE(MSG_COLOR, "Text Color")), // End, // Child, VGroup, Child, objs[ToolPen] = PoppenObject, MUIA_Window_Title, LOCALE(MSG_ADJUST, "Adjust Text Color"), MUIA_Draggable, TRUE, MUIA_ShortHelp, LOCALE(MSG_COLOR_HELP, "Color of the tool texts."), End, Child, Label2(LOCALE(MSG_FONT, "Text Font")), Child, data->FontASL = PopaslObject, MUIA_Popstring_String, objs[ToolFont] = String(0,35), MUIA_Popstring_Button, PopButton(MUII_PopUp), MUIA_Popasl_Type , ASL_FontRequest, ASLFO_TitleText , LOCALE(MSG_SELECT, "Please select a text font..."), End, // End, End, Child, RectangleObject, End, End, End, End, // Sløringseffekt: Normal, 3D, ... End, /* Child, HGroup, Child, HGroup, MUIA_Background, MUII_GroupBack, MUIA_Frame , MUIV_Frame_Group, MUIA_FrameTitle, LOCALE(MSG_BORDERTYPE, "Border Type"), InnerSpacing(12, 12), Child, objs[BorderType] = Cycle(BorderTypeStrings), End, Child, VGroup, MUIA_Background, MUII_GroupBack, MUIA_Frame , MUIV_Frame_Group, MUIA_FrameTitle, LOCALE(MSG_SELECTIONMODE, "Selection Border"), InnerSpacing(12, 12), Child, objs[SelectionMode] = Cycle(SelectionModeStrings), Child, HGroup, Child, Label2(LOCALE(MSG_AUTOACTIVE, "Show Active on Mousehi")), Child, objs[AutoActive] = CheckMark(TRUE), End, End, End, */ Child, HGroup, Child, HGroup, MUIA_Background, MUII_GroupBack, MUIA_Frame , MUIV_Frame_Group, MUIA_FrameTitle, LOCALE(MSG_BORDERTYPE, "Border Type"), Child, RectangleObject, End, Child, VGroup, Child, RectangleObject, End, Child, objs[BorderType] = Cycle(BorderTypeStrings), Child, RectangleObject, End, End, Child, RectangleObject, End, End, Child, HGroup, MUIA_Background, MUII_GroupBack, MUIA_Frame , MUIV_Frame_Group, MUIA_FrameTitle, LOCALE(MSG_SELECTIONMODE, "Selection Border"), Child, RectangleObject, End, Child, VGroup, Child, RectangleObject, End, MUIA_Weight, 200, Child, objs[SelectionMode] = Cycle(SelectionModeStrings), Child, HGroup, Child, Label2(LOCALE(MSG_AUTOACTIVE, "Show Active on Mousehit")), Child, objs[AutoActive] = CheckMark(TRUE), End, Child, RectangleObject, End, End, Child, RectangleObject, End, End, End, Child, TextObject, TextFrame, MUIA_Background, MUII_TextBack, MUIA_FixHeightTxt, "\n\n", MUIA_Text_Contents, ABOUTTEXT, End, End; if(prefsgroup) { DoMethod(objs[Look], MUIM_Notify, MUIA_Radio_Active, 0, textgroup, 6, MUIM_MultiSet, MUIA_Disabled, FALSE, textgroup, imagegroup, objs[InnerSpace_Text]); DoMethod(objs[Look], MUIM_Notify, MUIA_Radio_Active, 1, textgroup, 5, MUIM_MultiSet, MUIA_Disabled, TRUE, textgroup, objs[InnerSpace_Text]); DoMethod(objs[Look], MUIM_Notify, MUIA_Radio_Active, 2, textgroup, 5, MUIM_MultiSet, MUIA_Disabled, FALSE, textgroup, objs[InnerSpace_Text]); DoMethod(objs[Look], MUIM_Notify, MUIA_Radio_Active, 0, objs[InnerSpace_NoText], 3, MUIM_Set, MUIA_Disabled, TRUE); DoMethod(objs[Look], MUIM_Notify, MUIA_Radio_Active, 1, imagegroup, 5, MUIM_MultiSet, MUIA_Disabled, FALSE, imagegroup, objs[InnerSpace_NoText]); DoMethod(objs[Look], MUIM_Notify, MUIA_Radio_Active, 2, imagegroup, 5, MUIM_MultiSet, MUIA_Disabled, TRUE, imagegroup, objs[InnerSpace_NoText]); } return prefsgroup; }
void __cdecl Sphere(ObjectMaster* _this) { Cycle(_this, "SPHERE", ChaoEmotiball_Normal, ChaoEmotiball_None, GetChaoData(_this)->BallType); }
bool ASIM_COMMON_SYSTEM_CLASS::SYS_Execute( const UINT64 stop_nanosecond, const UINT64 stop_cycle, const UINT64 stop_inst, const UINT64 stop_macroinst, const UINT64 stop_packet) { static bool is_stats_on = false; static bool is_events_on = false; extern UINT64 trackCycle; UINT64 start_marker = SYS_CommittedMarkers(); UINT64 stop_marker = start_marker + 1; // Note: could generalize this ^ for committing N markers rather than 1 T1("Warming up"); myWarmupManager.DoWarmUp(); T1("Executing until cycle " << stop_cycle << " or inst " << stop_inst); while (!sysBreak && (SYS_Cycle() < stop_cycle) && (SYS_GlobalCommittedInsts() < stop_inst) && (SYS_GlobalCommittedMacroInsts() < stop_macroinst) && SYS_CommittedMarkers() < stop_marker) { if (is_stats_on != statsOn) { cerr << "Turned statistics collection " << (statsOn ? "on" : "off") << " @ cycle " << SYS_Cycle() << endl; is_stats_on = statsOn; } if (is_events_on != eventsOn) { cerr << "Turned events collection " << (eventsOn ? "on" : "off") << " @ cycle " << SYS_Cycle() << endl; is_events_on = eventsOn; } // cycle event notification DRALEVENT(Cycle(SYS_Cycle())); myChip.Clock(SYS_Cycle()); myContextScheduler.Clock(SYS_Cycle()); // Calling the thermal model at this level to avoid problems with DFVS, sleep states // and similar potential problems. myThermalModel->UpdateTemperature(SYS_Cycle()); // // Call the strip chart routines to dump the data if it is required. // DumpStripCharts(SYS_Cycle()); // increment the system clock here SYS_Cycle()++; /* setting global_cycle is a convenience for the ASSERT macro * mesgs */ global_cycle = SYS_Cycle(); statCycles++; // inc_nonDrainCycles() will examine a flag to decide whether need to ++nonDrainCycles; inc_nonDrainCycles(); trackCycle = SYS_Cycle(); } T1(SYS_Cycle() << ": SYS_Execute hit marker " << commitWatchMarker << " " << SYS_CommittedMarkers() - start_marker << " times"); if (SYS_CommittedMarkers() > stop_marker) { printf("WARNING: cycle "FMT64U": "FMT64D" markers have been commited -" " scheduled only "FMT64D"\n", SYS_Cycle(), SYS_CommittedMarkers() - start_marker, stop_marker - start_marker); } if (SYS_CommittedMarkers() >= stop_marker) { // watch is self-resetting when triggered commitWatchMarker = -1; // Note: we need to make sure here that the scheduler gets a // stop event, otherwise its going to turn around on the spot and // execute again, without any more action scheduled to stop it! CMD_Stop(ACTION_NOW); } return(!sysBreak); }
const Rotation operator-(const Rotation other) const { return Rotation(Cycle(_radians - other._radians)); }
constexpr const Rotation operator-() const { return Rotation(Cycle(-_radians)); }
Rotation& operator-=(const Rotation& other) { _radians = Cycle(_radians - other._radians); return *this; }
void __cdecl MouthTex(ObjectMaster* _this) { Cycle(_this, "MOUTH", ChaoMouth_None, ChaoMouth_SquigglyMoustache2, GetChaoData(_this)->MouthType); }
LLBoundListener LLEventPump::listen_impl(const std::string& name, const LLEventListener& listener, const NameList& after, const NameList& before) { // Check for duplicate name before connecting listener to mSignal ConnectionMap::const_iterator found = mConnections.find(name); // In some cases the user might disconnect a connection explicitly -- or // might use LLEventTrackable to disconnect implicitly. Either way, we can // end up retaining in mConnections a zombie connection object that's // already been disconnected. Such a connection object can't be // reconnected -- nor, in the case of LLEventTrackable, would we want to // try, since disconnection happens with the destruction of the listener // object. That means it's safe to overwrite a disconnected connection // object with the new one we're attempting. The case we want to prevent // is only when the existing connection object is still connected. if (found != mConnections.end() && found->second.connected()) { throw DupListenerName(std::string("Attempt to register duplicate listener name '") + name + "' on " + typeid(*this).name() + " '" + getName() + "'"); } // Okay, name is unique, try to reconcile its dependencies. Specify a new // "node" value that we never use for an mSignal placement; we'll fix it // later. DependencyMap::node_type& newNode = mDeps.add(name, -1.0, after, before); // What if this listener has been added, removed and re-added? In that // case newNode already has a non-negative value because we never remove a // listener from mDeps. But keep processing uniformly anyway in case the // listener was added back with different dependencies. Then mDeps.sort() // would put it in a different position, and the old newNode placement // value would be wrong, so we'd have to reassign it anyway. Trust that // re-adding a listener with the same dependencies is the trivial case for // mDeps.sort(): it can just replay its cache. DependencyMap::sorted_range sorted_range; try { // Can we pick an order that works including this new entry? sorted_range = mDeps.sort(); } catch (const DependencyMap::Cycle& e) { // No: the new node's after/before dependencies have made mDeps // unsortable. If we leave the new node in mDeps, it will continue // to screw up all future attempts to sort()! Pull it out. mDeps.remove(name); throw Cycle(std::string("New listener '") + name + "' on " + typeid(*this).name() + " '" + getName() + "' would cause cycle: " + e.what()); } // Walk the list to verify that we haven't changed the order. float previous = 0.0, myprev = 0.0; DependencyMap::sorted_iterator mydmi = sorted_range.end(); // need this visible after loop for (DependencyMap::sorted_iterator dmi = sorted_range.begin(); dmi != sorted_range.end(); ++dmi) { // Since we've added the new entry with an invalid placement, // recognize it and skip it. if (dmi->first == name) { // Remember the iterator belonging to our new node, and which // placement value was 'previous' at that point. mydmi = dmi; myprev = previous; continue; } // If the new node has rearranged the existing nodes, we'll find // that their placement values are no longer in increasing order. if (dmi->second < previous) { // This is another scenario in which we'd better back out the // newly-added node from mDeps -- but don't do it yet, we want to // traverse the existing mDeps to report on it! // Describe the change to the order of our listeners. Copy // everything but the newest listener to a vector we can sort to // obtain the old order. typedef std::vector< std::pair<float, std::string> > SortNameList; SortNameList sortnames; for (DependencyMap::sorted_iterator cdmi(sorted_range.begin()), cdmend(sorted_range.end()); cdmi != cdmend; ++cdmi) { if (cdmi->first != name) { sortnames.push_back(SortNameList::value_type(cdmi->second, cdmi->first)); } } std::sort(sortnames.begin(), sortnames.end()); std::ostringstream out; out << "New listener '" << name << "' on " << typeid(*this).name() << " '" << getName() << "' would move previous listener '" << dmi->first << "'\nwas: "; SortNameList::const_iterator sni(sortnames.begin()), snend(sortnames.end()); if (sni != snend) { out << sni->second; while (++sni != snend) { out << ", " << sni->second; } } out << "\nnow: "; DependencyMap::sorted_iterator ddmi(sorted_range.begin()), ddmend(sorted_range.end()); if (ddmi != ddmend) { out << ddmi->first; while (++ddmi != ddmend) { out << ", " << ddmi->first; } } // NOW remove the offending listener node. mDeps.remove(name); // Having constructed a description of the order change, inform caller. throw OrderChange(out.str()); } // This node becomes the previous one. previous = dmi->second; } // We just got done with a successful mDeps.add(name, ...) call. We'd // better have found 'name' somewhere in that sorted list! assert(mydmi != sorted_range.end()); // Four cases: // 0. name is the only entry: placement 1.0 // 1. name is the first of several entries: placement (next placement)/2 // 2. name is between two other entries: placement (myprev + (next placement))/2 // 3. name is the last entry: placement ceil(myprev) + 1.0 // Since we've cleverly arranged for myprev to be 0.0 if name is the // first entry, this folds down to two cases. Case 1 is subsumed by // case 2, and case 0 is subsumed by case 3. So we need only handle // cases 2 and 3, which means we need only detect whether name is the // last entry. Increment mydmi to see if there's anything beyond. if (++mydmi != sorted_range.end()) { // The new node isn't last. Place it between the previous node and // the successor. newNode = (myprev + mydmi->second)/2.0; } else { // The new node is last. Bump myprev up to the next integer, add // 1.0 and use that. newNode = std::ceil(myprev) + 1.0; } // Now that newNode has a value that places it appropriately in mSignal, // connect it. LLBoundListener bound = mSignal->connect(newNode, listener); mConnections[name] = bound; return bound; }
//coordinate descent for a single lambda. void CoordinateDescent(int node,double *beta,double lambda,double *inprod,double *fprod,int *eorder,double *rsq,double eps,int *iter,double *sigma,double *norm,int *obsleng,int *eorleng) { int i,j,k,node2=node*node,rn,pn,rindex,pindex,active_length; int *G,*tG,*active,*eor; double b1,b2,cbeta1,cbeta2,dif1=0,dif2=0,rsq1=*rsq,rsq2=*rsq,mad; double denom1,denom2; double rnorm1,rnorm2,rsig1,rsig2,pnorm1,pnorm2,psig1,psig2, absum1,absum2,tmpSigSq1,tmpSigSq2,bda1,bda2, Delta1,Delta2,root1,root2,root3,tmpCoef1,tmpCoef2,tmpCoef3,dLoss1,dLoss2,dLoss3; G=(int *) Calloc(node2,int); tG=(int *) Calloc(node2,int); for (i=0;i<node2;i++) { if(beta[i]!=0) G[i]=1; else G[i]=0; } while(1) { *iter+=1; active=(int *) Calloc((node2-node)/2,int); active_length=0; mad=0.0; eor=eorder; for(i=0;i<*eorleng;i++) { rn=*eor++; pn=*eor++; pindex=(pn-1)*node+rn-1; rindex=(rn-1)*node+pn-1; for (j=0;j<node2;j++) tG[j]=G[j]; tG[rindex]=tG[pindex]=0; b1=beta[rindex]; b2=beta[pindex]; if(Cycle(node,tG,rn,pn)) { denom1=fprod[(rn-1)*node2+(pn-1)*(node+1)]; rnorm2=norm[rn-1]+2*b1*inprod[rindex]+denom1*b1*b1; absum1=inprod[rindex]+denom1*b1; tmpSigSq1=rnorm2/obsleng[rn-1]; bda1=0.5*obsleng[rn-1]*denom1/(lambda*lambda); Delta1=bda1*bda1-(denom1*rnorm2-absum1*absum1)/(lambda*lambda); if(absum1>lambda*tmpSigSq1) { rsig1=bda1-sqrt(Delta1); cbeta1=(absum1-lambda*rsig1)/denom1; } else if(absum1<(-lambda*tmpSigSq1)) { rsig1=bda1-sqrt(Delta1); cbeta1=(absum1+lambda*rsig1)/denom1; } else if(Delta1>=0 && fabs(absum1)>lambda*bda1) { root1=bda1+sqrt(Delta1); root2=bda1-sqrt(Delta1); root3=tmpSigSq1; if(absum1>0) { tmpCoef1=(absum1-lambda*root1)/denom1; tmpCoef2=(absum1-lambda*root2)/denom1; tmpCoef3=0; } else { tmpCoef1=(absum1+lambda*root1)/denom1; tmpCoef2=(absum1+lambda*root2)/denom1; tmpCoef3=0; } dLoss1=0.5*obsleng[rn-1]*log(root1)+lambda*fabs(tmpCoef1); dLoss2=0.5*obsleng[rn-1]*log(root2)+lambda*fabs(tmpCoef2); dLoss3=0.5*obsleng[rn-1]*log(root3)+lambda*fabs(tmpCoef3); rsig1= (dLoss1<dLoss2) ? ((dLoss1<dLoss3) ? root1 : root3) : ((dLoss2<dLoss3) ? root2 : root3); cbeta1= (dLoss1<dLoss2) ? ((dLoss1<dLoss3) ? tmpCoef1 : tmpCoef3) : ((dLoss2<dLoss3) ? tmpCoef2 : tmpCoef3); } else { rsig1=tmpSigSq1; cbeta1=0; } dif1=cbeta1-b1; if(dif1!=0) { rnorm1=norm[rn-1]-2*dif1*inprod[rindex]+denom1*dif1*dif1; *rsq=*rsq+0.5*obsleng[rn-1]*log(rsig1/sigma[rn-1])+lambda*(fabs(cbeta1)-fabs(b1)); beta[rindex]=cbeta1; norm[rn-1]=rnorm1; sigma[rn-1]=rsig1; for (k=(rn-1)*node;k<rn*node;k++) { inprod[k]-=fprod[(rn-1)*(node2-node)+(pn-1)*node+k]*dif1; } } if(cbeta1!=0) { G[rindex]=1; active[active_length]=i; active_length++; } else G[rindex]=0; mad=Max(fabs(dif1),mad); } else if(Cycle(node,tG,pn,rn)) { denom2=fprod[(pn-1)*node2+(rn-1)*(node+1)]; pnorm1=norm[pn-1]+2*b2*inprod[pindex]+denom2*b2*b2; absum2=inprod[pindex]+denom2*b2; tmpSigSq2=pnorm1/obsleng[pn-1]; bda2=0.5*obsleng[pn-1]*denom2/(lambda*lambda); Delta2=bda2*bda2-(denom2*pnorm1-absum2*absum2)/(lambda*lambda); if(absum2>lambda*tmpSigSq2) { psig2=bda2-sqrt(Delta2); cbeta2=(absum2-lambda*psig2)/denom2; } else if(absum2<(-lambda*tmpSigSq2)) { psig2=bda2-sqrt(Delta2); cbeta2=(absum2+lambda*psig2)/denom2; } else if(Delta2>=0 && fabs(absum2)>lambda*bda2) { root1=bda2+sqrt(Delta2); root2=bda2-sqrt(Delta2); root3=tmpSigSq2; if(absum2>0) { tmpCoef1=(absum2-lambda*root1)/denom2; tmpCoef2=(absum2-lambda*root2)/denom2; tmpCoef3=0; } else { tmpCoef1=(absum2+lambda*root1)/denom2; tmpCoef2=(absum2+lambda*root2)/denom2; tmpCoef3=0; } dLoss1=0.5*obsleng[pn-1]*log(root1)+lambda*fabs(tmpCoef1); dLoss2=0.5*obsleng[pn-1]*log(root2)+lambda*fabs(tmpCoef2); dLoss3=0.5*obsleng[pn-1]*log(root3)+lambda*fabs(tmpCoef3); psig2= (dLoss1<dLoss2) ? ((dLoss1<dLoss3) ? root1 : root3) : ((dLoss2<dLoss3) ? root2 : root3); cbeta2= (dLoss1<dLoss2) ? ((dLoss1<dLoss3) ? tmpCoef1 : tmpCoef3) : ((dLoss2<dLoss3) ? tmpCoef2 : tmpCoef3); } else { psig2=tmpSigSq2; cbeta2=0; } dif2=cbeta2-b2; if(dif2!=0) { pnorm2=norm[pn-1]-2*dif2*inprod[pindex]+denom2*dif2*dif2; *rsq=*rsq+0.5*obsleng[pn-1]*log(psig2/sigma[pn-1])+lambda*(fabs(cbeta2)-fabs(b2)); beta[pindex]=cbeta2; norm[pn-1]=pnorm2; sigma[pn-1]=psig2; for (k=(pn-1)*node;k<pn*node;k++) { inprod[k]-=fprod[(pn-1)*(node2-node)+(rn-1)*node+k]*dif2; } } if(cbeta2!=0) { G[pindex]=1; active[active_length]=i; active_length++; } else G[pindex]=0; mad=Max(fabs(dif2),mad); } else { denom1=fprod[(rn-1)*node2+(pn-1)*(node+1)]; denom2=fprod[(pn-1)*node2+(rn-1)*(node+1)]; rnorm2=norm[rn-1]+2*b1*inprod[rindex]+denom1*b1*b1; absum1=inprod[rindex]+denom1*b1; tmpSigSq1=rnorm2/obsleng[rn-1]; bda1=0.5*obsleng[rn-1]*denom1/(lambda*lambda); Delta1=bda1*bda1-(denom1*rnorm2-absum1*absum1)/(lambda*lambda); if(absum1>lambda*tmpSigSq1) { rsig1=bda1-sqrt(Delta1); cbeta1=(absum1-lambda*rsig1)/denom1; } else if(absum1<(-lambda*tmpSigSq1)) { rsig1=bda1-sqrt(Delta1); cbeta1=(absum1+lambda*rsig1)/denom1; } else if(Delta1>=0 && fabs(absum1)>lambda*bda1) { root1=bda1+sqrt(Delta1); root2=bda1-sqrt(Delta1); root3=tmpSigSq1; if(absum1>0) { tmpCoef1=(absum1-lambda*root1)/denom1; tmpCoef2=(absum1-lambda*root2)/denom1; tmpCoef3=0; } else { tmpCoef1=(absum1+lambda*root1)/denom1; tmpCoef2=(absum1+lambda*root2)/denom1; tmpCoef3=0; } dLoss1=0.5*obsleng[rn-1]*log(root1)+lambda*fabs(tmpCoef1); dLoss2=0.5*obsleng[rn-1]*log(root2)+lambda*fabs(tmpCoef2); dLoss3=0.5*obsleng[rn-1]*log(root3)+lambda*fabs(tmpCoef3); rsig1= (dLoss1<dLoss2) ? ((dLoss1<dLoss3) ? root1 : root3) : ((dLoss2<dLoss3) ? root2 : root3); cbeta1= (dLoss1<dLoss2) ? ((dLoss1<dLoss3) ? tmpCoef1 : tmpCoef3) : ((dLoss2<dLoss3) ? tmpCoef2 : tmpCoef3); } else { rsig1=tmpSigSq1; cbeta1=0; } dif1=cbeta1-b1; rnorm1=norm[rn-1]-2*dif1*inprod[rindex]+denom1*dif1*dif1; pnorm1=norm[pn-1]+2*b2*inprod[pindex]+denom2*b2*b2; absum2=inprod[pindex]+denom2*b2; tmpSigSq2=pnorm1/obsleng[pn-1]; bda2=0.5*obsleng[pn-1]*denom2/(lambda*lambda); Delta2=bda2*bda2-(denom2*pnorm1-absum2*absum2)/(lambda*lambda); if(absum2>lambda*tmpSigSq2) { psig2=bda2-sqrt(Delta2); cbeta2=(absum2-lambda*psig2)/denom2; } else if(absum2<(-lambda*tmpSigSq2)) { psig2=bda2-sqrt(Delta2); cbeta2=(absum2+lambda*psig2)/denom2; } else if(Delta2>=0 && fabs(absum2)>lambda*bda2) { root1=bda2+sqrt(Delta2); root2=bda2-sqrt(Delta2); root3=tmpSigSq2; if(absum2>0) { tmpCoef1=(absum2-lambda*root1)/denom2; tmpCoef2=(absum2-lambda*root2)/denom2; tmpCoef3=0; } else { tmpCoef1=(absum2+lambda*root1)/denom2; tmpCoef2=(absum2+lambda*root2)/denom2; tmpCoef3=0; } dLoss1=0.5*obsleng[pn-1]*log(root1)+lambda*fabs(tmpCoef1); dLoss2=0.5*obsleng[pn-1]*log(root2)+lambda*fabs(tmpCoef2); dLoss3=0.5*obsleng[pn-1]*log(root3)+lambda*fabs(tmpCoef3); psig2= (dLoss1<dLoss2) ? ((dLoss1<dLoss3) ? root1 : root3) : ((dLoss2<dLoss3) ? root2 : root3); cbeta2= (dLoss1<dLoss2) ? ((dLoss1<dLoss3) ? tmpCoef1 : tmpCoef3) : ((dLoss2<dLoss3) ? tmpCoef2 : tmpCoef3); } else { psig2=tmpSigSq2; cbeta2=0; } dif2=cbeta2-b2; pnorm2=norm[pn-1]-2*dif2*inprod[pindex]+denom2*dif2*dif2; psig1=pnorm1/obsleng[pn-1]; rsig2=rnorm2/obsleng[rn-1]; rsq1=*rsq+0.5*obsleng[rn-1]*log(rsig1/sigma[rn-1])+lambda*(fabs(cbeta1)-fabs(b1)) +0.5*obsleng[pn-1]*log(psig1/sigma[pn-1])-lambda*fabs(b2); rsq2=*rsq+0.5*obsleng[rn-1]*log(rsig2/sigma[rn-1])-lambda*fabs(b1) +0.5*obsleng[pn-1]*log(psig2/sigma[pn-1])+lambda*(fabs(cbeta2)-fabs(b2)); if(rsq1<=rsq2) { *rsq=rsq1; if(dif1!=0) { beta[rindex]=cbeta1; norm[rn-1]=rnorm1; sigma[rn-1]=rsig1; for (k=(rn-1)*node;k<rn*node;k++) { inprod[k]-=fprod[(rn-1)*(node2-node)+(pn-1)*node+k]*dif1; } } if(b2!=0) { beta[pindex]=0.0; norm[pn-1]=pnorm1; sigma[pn-1]=psig1; dif2=-b2; for (k=(pn-1)*node;k<pn*node;k++) { inprod[k]-=fprod[(pn-1)*(node2-node)+(rn-1)*node+k]*dif2; } } if(cbeta1!=0) { G[rindex]=1; active[active_length]=i; active_length++; } else G[rindex]=0; G[pindex]=0; mad=Max(Max(fabs(dif1),fabs(b2)),mad); } else { *rsq=rsq2; if(b1!=0) { beta[rindex]=0.0; norm[rn-1]=rnorm2; sigma[rn-1]=rsig2; dif1=-b1; for (k=(rn-1)*node;k<rn*node;k++) { inprod[k]-=fprod[(rn-1)*(node2-node)+(pn-1)*node+k]*dif1; } } if(dif2!=0) { beta[pindex]=cbeta2; norm[pn-1]=pnorm2; sigma[pn-1]=psig2; for (k=(pn-1)*node;k<pn*node;k++) { inprod[k]-=fprod[(pn-1)*(node2-node)+(rn-1)*node+k]*dif2; } } if(cbeta2!=0) { G[pindex]=1; active[active_length]=i; active_length++; } else G[pindex]=0; G[rindex]=0; mad=Max(Max(fabs(b1),fabs(dif2)),mad); } } } if(mad<eps) { Free(active); break; } //active set convergence while(1) { mad=0.0; for(i=0;i<active_length;i++) { rn=eorder[active[i]*2]; pn=eorder[active[i]*2+1]; pindex=(pn-1)*node+rn-1; rindex=(rn-1)*node+pn-1; for (j=0;j<node2;j++) tG[j]=G[j]; tG[rindex]=tG[pindex]=0; b1=beta[rindex]; b2=beta[pindex]; if(Cycle(node,tG,rn,pn)) { denom1=fprod[(rn-1)*node2+(pn-1)*(node+1)]; rnorm2=norm[rn-1]+2*b1*inprod[rindex]+denom1*b1*b1; absum1=inprod[rindex]+denom1*b1; tmpSigSq1=rnorm2/obsleng[rn-1]; bda1=0.5*obsleng[rn-1]*denom1/(lambda*lambda); Delta1=bda1*bda1-(denom1*rnorm2-absum1*absum1)/(lambda*lambda); if(absum1>lambda*tmpSigSq1) { rsig1=bda1-sqrt(Delta1); cbeta1=(absum1-lambda*rsig1)/denom1; } else if(absum1<(-lambda*tmpSigSq1)) { rsig1=bda1-sqrt(Delta1); cbeta1=(absum1+lambda*rsig1)/denom1; } else if(Delta1>=0 && fabs(absum1)>lambda*bda1) { root1=bda1+sqrt(Delta1); root2=bda1-sqrt(Delta1); root3=tmpSigSq1; if(absum1>0) { tmpCoef1=(absum1-lambda*root1)/denom1; tmpCoef2=(absum1-lambda*root2)/denom1; tmpCoef3=0; } else { tmpCoef1=(absum1+lambda*root1)/denom1; tmpCoef2=(absum1+lambda*root2)/denom1; tmpCoef3=0; } dLoss1=0.5*obsleng[rn-1]*log(root1)+lambda*fabs(tmpCoef1); dLoss2=0.5*obsleng[rn-1]*log(root2)+lambda*fabs(tmpCoef2); dLoss3=0.5*obsleng[rn-1]*log(root3)+lambda*fabs(tmpCoef3); rsig1= (dLoss1<dLoss2) ? ((dLoss1<dLoss3) ? root1 : root3) : ((dLoss2<dLoss3) ? root2 : root3); cbeta1= (dLoss1<dLoss2) ? ((dLoss1<dLoss3) ? tmpCoef1 : tmpCoef3) : ((dLoss2<dLoss3) ? tmpCoef2 : tmpCoef3); } else { rsig1=tmpSigSq1; cbeta1=0; } dif1=cbeta1-b1; if(dif1!=0) { rnorm1=norm[rn-1]-2*dif1*inprod[rindex]+denom1*dif1*dif1; *rsq=*rsq+0.5*obsleng[rn-1]*log(rsig1/sigma[rn-1])+lambda*(fabs(cbeta1)-fabs(b1)); beta[rindex]=cbeta1; norm[rn-1]=rnorm1; sigma[rn-1]=rsig1; for (k=(rn-1)*node;k<rn*node;k++) { inprod[k]-=fprod[(rn-1)*(node2-node)+(pn-1)*node+k]*dif1; } } if(cbeta1!=0) { G[rindex]=1; } else G[rindex]=0; mad=Max(fabs(dif1),mad); } else if(Cycle(node,tG,pn,rn)) { denom2=fprod[(pn-1)*node2+(rn-1)*(node+1)]; pnorm1=norm[pn-1]+2*b2*inprod[pindex]+denom2*b2*b2; absum2=inprod[pindex]+denom2*b2; tmpSigSq2=pnorm1/obsleng[pn-1]; bda2=0.5*obsleng[pn-1]*denom2/(lambda*lambda); Delta2=bda2*bda2-(denom2*pnorm1-absum2*absum2)/(lambda*lambda); if(absum2>lambda*tmpSigSq2) { psig2=bda2-sqrt(Delta2); cbeta2=(absum2-lambda*psig2)/denom2; } else if(absum2<(-lambda*tmpSigSq2)) { psig2=bda2-sqrt(Delta2); cbeta2=(absum2+lambda*psig2)/denom2; } else if(Delta2>=0 && fabs(absum2)>lambda*bda2) { root1=bda2+sqrt(Delta2); root2=bda2-sqrt(Delta2); root3=tmpSigSq2; if(absum2>0) { tmpCoef1=(absum2-lambda*root1)/denom2; tmpCoef2=(absum2-lambda*root2)/denom2; tmpCoef3=0; } else { tmpCoef1=(absum2+lambda*root1)/denom2; tmpCoef2=(absum2+lambda*root2)/denom2; tmpCoef3=0; } dLoss1=0.5*obsleng[pn-1]*log(root1)+lambda*fabs(tmpCoef1); dLoss2=0.5*obsleng[pn-1]*log(root2)+lambda*fabs(tmpCoef2); dLoss3=0.5*obsleng[pn-1]*log(root3)+lambda*fabs(tmpCoef3); psig2= (dLoss1<dLoss2) ? ((dLoss1<dLoss3) ? root1 : root3) : ((dLoss2<dLoss3) ? root2 : root3); cbeta2= (dLoss1<dLoss2) ? ((dLoss1<dLoss3) ? tmpCoef1 : tmpCoef3) : ((dLoss2<dLoss3) ? tmpCoef2 : tmpCoef3); } else { psig2=tmpSigSq2; cbeta2=0; } dif2=cbeta2-b2; if(dif2!=0) { pnorm2=norm[pn-1]-2*dif2*inprod[pindex]+denom2*dif2*dif2; *rsq=*rsq+0.5*obsleng[pn-1]*log(psig2/sigma[pn-1])+lambda*(fabs(cbeta2)-fabs(b2)); beta[pindex]=cbeta2; norm[pn-1]=pnorm2; sigma[pn-1]=psig2; for (k=(pn-1)*node;k<pn*node;k++) { inprod[k]-=fprod[(pn-1)*(node2-node)+(rn-1)*node+k]*dif2; } } if(cbeta2!=0) { G[pindex]=1; } else G[pindex]=0; mad=Max(fabs(dif2),mad); } else { denom1=fprod[(rn-1)*node2+(pn-1)*(node+1)]; denom2=fprod[(pn-1)*node2+(rn-1)*(node+1)]; rnorm2=norm[rn-1]+2*b1*inprod[rindex]+denom1*b1*b1; absum1=inprod[rindex]+denom1*b1; tmpSigSq1=rnorm2/obsleng[rn-1]; bda1=0.5*obsleng[rn-1]*denom1/(lambda*lambda); Delta1=bda1*bda1-(denom1*rnorm2-absum1*absum1)/(lambda*lambda); if(absum1>lambda*tmpSigSq1) { rsig1=bda1-sqrt(Delta1); cbeta1=(absum1-lambda*rsig1)/denom1; } else if(absum1<(-lambda*tmpSigSq1)) { rsig1=bda1-sqrt(Delta1); cbeta1=(absum1+lambda*rsig1)/denom1; } else if(Delta1>=0 && fabs(absum1)>lambda*bda1) { root1=bda1+sqrt(Delta1); root2=bda1-sqrt(Delta1); root3=tmpSigSq1; if(absum1>0) { tmpCoef1=(absum1-lambda*root1)/denom1; tmpCoef2=(absum1-lambda*root2)/denom1; tmpCoef3=0; } else { tmpCoef1=(absum1+lambda*root1)/denom1; tmpCoef2=(absum1+lambda*root2)/denom1; tmpCoef3=0; } dLoss1=0.5*obsleng[rn-1]*log(root1)+lambda*fabs(tmpCoef1); dLoss2=0.5*obsleng[rn-1]*log(root2)+lambda*fabs(tmpCoef2); dLoss3=0.5*obsleng[rn-1]*log(root3)+lambda*fabs(tmpCoef3); rsig1= (dLoss1<dLoss2) ? ((dLoss1<dLoss3) ? root1 : root3) : ((dLoss2<dLoss3) ? root2 : root3); cbeta1= (dLoss1<dLoss2) ? ((dLoss1<dLoss3) ? tmpCoef1 : tmpCoef3) : ((dLoss2<dLoss3) ? tmpCoef2 : tmpCoef3); } else { rsig1=tmpSigSq1; cbeta1=0; } dif1=cbeta1-b1; rnorm1=norm[rn-1]-2*dif1*inprod[rindex]+denom1*dif1*dif1; pnorm1=norm[pn-1]+2*b2*inprod[pindex]+denom2*b2*b2; absum2=inprod[pindex]+denom2*b2; tmpSigSq2=pnorm1/obsleng[pn-1]; bda2=0.5*obsleng[pn-1]*denom2/(lambda*lambda); Delta2=bda2*bda2-(denom2*pnorm1-absum2*absum2)/(lambda*lambda); if(absum2>lambda*tmpSigSq2) { psig2=bda2-sqrt(Delta2); cbeta2=(absum2-lambda*psig2)/denom2; } else if(absum2<(-lambda*tmpSigSq2)) { psig2=bda2-sqrt(Delta2); cbeta2=(absum2+lambda*psig2)/denom2; } else if(Delta2>=0 && fabs(absum2)>lambda*bda2) { root1=bda2+sqrt(Delta2); root2=bda2-sqrt(Delta2); root3=tmpSigSq2; if(absum2>0) { tmpCoef1=(absum2-lambda*root1)/denom2; tmpCoef2=(absum2-lambda*root2)/denom2; tmpCoef3=0; } else { tmpCoef1=(absum2+lambda*root1)/denom2; tmpCoef2=(absum2+lambda*root2)/denom2; tmpCoef3=0; } dLoss1=0.5*obsleng[pn-1]*log(root1)+lambda*fabs(tmpCoef1); dLoss2=0.5*obsleng[pn-1]*log(root2)+lambda*fabs(tmpCoef2); dLoss3=0.5*obsleng[pn-1]*log(root3)+lambda*fabs(tmpCoef3); psig2= (dLoss1<dLoss2) ? ((dLoss1<dLoss3) ? root1 : root3) : ((dLoss2<dLoss3) ? root2 : root3); cbeta2= (dLoss1<dLoss2) ? ((dLoss1<dLoss3) ? tmpCoef1 : tmpCoef3) : ((dLoss2<dLoss3) ? tmpCoef2 : tmpCoef3); } else { psig2=tmpSigSq2; cbeta2=0; } dif2=cbeta2-b2; pnorm2=norm[pn-1]-2*dif2*inprod[pindex]+denom2*dif2*dif2; psig1=pnorm1/obsleng[pn-1]; rsig2=rnorm2/obsleng[rn-1]; rsq1=*rsq+0.5*obsleng[rn-1]*log(rsig1/sigma[rn-1])+lambda*(fabs(cbeta1)-fabs(b1)) +0.5*obsleng[pn-1]*log(psig1/sigma[pn-1])-lambda*fabs(b2); rsq2=*rsq+0.5*obsleng[rn-1]*log(rsig2/sigma[rn-1])-lambda*fabs(b1) +0.5*obsleng[pn-1]*log(psig2/sigma[pn-1])+lambda*(fabs(cbeta2)-fabs(b2)); if(rsq1<=rsq2) { *rsq=rsq1; if(dif1!=0) { beta[rindex]=cbeta1; norm[rn-1]=rnorm1; sigma[rn-1]=rsig1; for (k=(rn-1)*node;k<rn*node;k++) { inprod[k]-=fprod[(rn-1)*(node2-node)+(pn-1)*node+k]*dif1; } } if(b2!=0) { beta[pindex]=0.0; norm[pn-1]=pnorm1; sigma[pn-1]=psig1; dif2=-b2; for (k=(pn-1)*node;k<pn*node;k++) { inprod[k]-=fprod[(pn-1)*(node2-node)+(rn-1)*node+k]*dif2; } } if(cbeta1!=0) { G[rindex]=1; } else G[rindex]=0; G[pindex]=0; mad=Max(Max(fabs(dif1),fabs(b2)),mad); } else { *rsq=rsq2; if(b1!=0) { beta[rindex]=0.0; norm[rn-1]=rnorm2; sigma[rn-1]=rsig2; dif1=-b1; for (k=(rn-1)*node;k<rn*node;k++) { inprod[k]-=fprod[(rn-1)*(node2-node)+(pn-1)*node+k]*dif1; } } if(dif2!=0) { beta[pindex]=cbeta2; norm[pn-1]=pnorm2; sigma[pn-1]=psig2; for (k=(pn-1)*node;k<pn*node;k++) { inprod[k]-=fprod[(pn-1)*(node2-node)+(rn-1)*node+k]*dif2; } } if(cbeta2!=0) { G[pindex]=1; } else G[pindex]=0; G[rindex]=0; mad=Max(Max(fabs(b1),fabs(dif2)),mad); } } } if(mad<eps) break; } Free(active); } Free(G); Free(tG); eor=NULL; }
static GainType PatchCyclesRec(int k, int m, int M, GainType G0, LKH::LKHAlg *Alg) { LKH::LKHAlg::Node *s1, *s2, *s3, *s4, *s5, *s6, *S3 = 0, *S4 = 0; LKH::LKHAlg::Candidate *Ns2, *Ns4; GainType G1, G2, G3, G4, Gain, CloseUpGain, BestCloseUpGain = Alg->PatchingAExtended ? MINUS_INFINITY : 0; int X4, X6; int i, NewCycle, *cycleSaved = 0, *pSaved = 0; int Breadth2 = 0, Breadth4; s1 = (*t.get())[2 * k + 1]; s2 = (*t.get())[i = 2 * (k + m) - 2]; (*incl.get())[(*incl.get())[i] = i + 1] = i; /* Choose (s2,s3) as a candidate edge emanating from s2 */ for (Ns2 = s2->CandidateSet; (s3 = Ns2->To); Ns2++) { if (s3 == s2->Pred || s3 == s2->Suc || Added(s2, s3) || (NewCycle = Cycle(s3, k,Alg)) == *CurrentCycle) continue; if (++Breadth2 > Alg->MaxBreadth) break; MarkAdded(s2, s3); (*t.get())[2 * (k + m) - 1] = s3; G1 = G0 - Ns2->Cost; /* Choose s4 as one of s3's two neighbors on the tour */ for (X4 = 1; X4 <= 2; X4++) { s4 = X4 == 1 ? s3->Pred : s3->Suc; if ((Fixed(s3, s4) || Alg->IsCommonEdge(s3, s4)) || Deleted(s3, s4)) continue; MarkDeleted(s3, s4); (*t.get())[2 * (k + m)] = s4; G2 = G1 + (Alg->*(Alg->C))(s3, s4); if (M > 2) { if (!cycleSaved) { assert(cycleSaved = (int *) malloc(2 * k * sizeof(int))); memcpy(cycleSaved, cycle.get() + 1, 2 * k * sizeof(int)); } for (i = 1; i <= 2 * k; i++) if ((*cycle.get())[i] == NewCycle) (*cycle.get())[i] = *CurrentCycle; /* Extend the current alternating path */ if ((Gain = PatchCyclesRec(k, m + 1, M - 1, G2,Alg)) > 0) { UnmarkAdded(s2, s3); UnmarkDeleted(s3, s4); goto End_PatchCyclesRec; } memcpy(cycle.get() + 1, cycleSaved, 2 * k * sizeof(int)); if (Alg->PatchingA >= 2 && *Patchwork < Alg->Dimension && k + M < Alg->NonsequentialMoveType && !Alg->Forbidden(s4, s1) && (!Alg->PatchingARestricted || Alg->IsCandidate(s4, s1))) { GainType Bound = BestCloseUpGain >= 0 || Alg->IsCandidate(s4, s1) ? BestCloseUpGain : 0; if ((!Alg->c || G2 - (Alg->*(Alg->c))(s4, s1) > Bound) && (CloseUpGain = G2 - (Alg->*(Alg->C))(s4, s1)) > Bound) { S3 = s3; S4 = s4; BestCloseUpGain = CloseUpGain; } } } else if (!Alg->Forbidden(s4, s1) && (!Alg->c || G2 - (Alg->*(Alg->c))(s4, s1) > 0) && (Gain = G2 - (Alg->*(Alg->C))(s4, s1)) > 0) { (*incl.get())[(*incl.get())[2 * k + 1] = 2 * (k + m)] = 2 * k + 1; Alg->MakeKOptMove(k + m); UnmarkAdded(s2, s3); UnmarkDeleted(s3, s4); goto End_PatchCyclesRec; } UnmarkDeleted(s3, s4); } UnmarkAdded(s2, s3); } if (M == 2 && !Alg->PatchingCRestricted) { /* Try to patch the two cycles by a sequential 3-opt move */ (*incl.get())[(*incl.get())[2 * (k + m)] = 2 * (k + m) + 1] = 2 * (k + m); (*incl.get())[(*incl.get())[2 * k + 1] = 2 * (k + m) + 2] = 2 * k + 1; Breadth2 = 0; /* Choose (s2,s3) as a candidate edge emanating from s2 */ for (Ns2 = s2->CandidateSet; (s3 = Ns2->To); Ns2++) { if (s3 == s2->Pred || s3 == s2->Suc || Added(s2, s3)) continue; if (++Breadth2 > Alg->MaxBreadth) break; (*t.get())[2 * (k + m) - 1] = s3; G1 = G0 - Ns2->Cost; NewCycle = Cycle(s3, k,Alg); /* Choose s4 as one of s3's two neighbors on the tour */ for (X4 = 1; X4 <= 2; X4++) { s4 = X4 == 1 ? s3->Pred : s3->Suc; if ((Fixed(s3, s4) || Alg->IsCommonEdge(s3, s4)) || Deleted(s3, s4)) continue; (*t.get())[2 * (k + m)] = s4; G2 = G1 + (Alg->*(Alg->C))(s3, s4); Breadth4 = 0; /* Choose (s4,s5) as a candidate edge emanating from s4 */ for (Ns4 = s4->CandidateSet; (s5 = Ns4->To); Ns4++) { if (s5 == s4->Pred || s5 == s4->Suc || s5 == s1 || Added(s4, s5) || (NewCycle == *CurrentCycle && Cycle(s5, k,Alg) == *CurrentCycle)) continue; if (++Breadth4 > Alg->MaxBreadth) break; G3 = G2 - Ns4->Cost; /* Choose s6 as one of s5's two neighbors on the tour */ for (X6 = 1; X6 <= 2; X6++) { s6 = X6 == 1 ? s5->Pred : s5->Suc; if (s6 == s1 || Alg->Forbidden(s6, s1) || (Fixed(s5, s6) || Alg->IsCommonEdge(s5, s6)) || Deleted(s5, s6) || Added(s6, s1)) continue; G4 = G3 + (Alg->*(Alg->C))(s5, s6); if ((!Alg->c || G4 - (Alg->*(Alg->c))(s6, s1) > 0) && (Gain = G4 - (Alg->*(Alg->C))(s6, s1)) > 0) { if (!pSaved) { assert(pSaved = (int *) malloc(2 * k * sizeof(int))); memcpy(pSaved, p.get() + 1, 2 * k * sizeof(int)); } (*t.get())[2 * (k + m) + 1] = s5; (*t.get())[2 * (k + m) + 2] = s6; if (FeasibleKOptMove(k + m + 1)) { Alg->MakeKOptMove(k + m + 1); goto End_PatchCyclesRec; } memcpy(p.get() + 1, pSaved, 2 * k * sizeof(int)); for (i = 1; i <= 2 * k; i++) (*q.get())[(*p.get())[i]] = i; } } } } } } Gain = 0; if (S4) { int OldCycle = *CurrentCycle; if (!pSaved) { assert(pSaved = (int *) malloc(2 * k * sizeof(int))); memcpy(pSaved, p.get() + 1, 2 * k * sizeof(int)); } (*t.get())[2 * (k + m) - 1] = S3; (*t.get())[2 * (k + m)] = S4; (*incl.get())[(*incl.get())[2 * k + 1] = 2 * (k + m)] = 2 * k + 1; /* Find a new alternating cycle */ Alg->PatchingA--; (*RecLevel)++; MarkAdded(s2, S3); MarkDeleted(S3, S4); MarkAdded(S4, s1); Gain = Alg->PatchCycles(k + m, BestCloseUpGain); UnmarkAdded(s2, S3); UnmarkDeleted(S3, S4); UnmarkAdded(S4, s1); (*RecLevel)--; Alg->PatchingA++; if (Gain <= 0) { memcpy(cycle.get() + 1, cycleSaved, 2 * k * sizeof(int)); memcpy(p.get() + 1, pSaved, 2 * k * sizeof(int)); for (i = 1; i <= 2 * k; i++) (*q.get())[(*p.get())[i]] = i; *CurrentCycle = OldCycle; } } End_PatchCyclesRec: free(cycleSaved); free(pSaved); return Gain; }
void __cdecl EyeTex(ObjectMaster* _this) { Cycle(_this, "EYES", ChaoEyes_Normal, ChaoEyes_YellowChaos, GetChaoData(_this)->EyeType); }
void main( void ) { int Done = FALSE; ULONG sig; static STRPTR styleoptions[] = { "IRC", "Email", "HTML", NULL }; if( !( MUIMasterBase = OpenLibrary( MUIMASTER_NAME, 19 ) ) ) return; if( app = ApplicationObject, MUIA_Application_Title, "TextInputDemo", MUIA_Application_Version, "$VER: TextInput Demo 2.0", MUIA_Application_Copyright, "© 1997-99 by Oliver Wagner, All Rights Reserved", MUIA_Application_Author, "Oliver Wagner", MUIA_Application_Description, "Demo for Textinput.mcc", MUIA_Application_Base, "TEXTINPUT-DEMO", SubWindow, win = WindowObject, MUIA_Window_ID, 42, MUIA_Window_Title, "TextInput Demo", WindowContents, VGroup, Child, HGroup, Child, Label1( "Style:" ), Child, Cycle( styleoptions ), End, Child, HGroup, GroupFrameT( "Single line" ), Child, ColGroup( 2 ), Child, Label2( "Input:" ), Child, ti1 = TextinputObject, StringFrame, MUIA_CycleChain, 1, MUIA_ControlChar, 'a', MUIA_Textinput_Multiline, FALSE, MUIA_Textinput_Contents, C1, End, Child, Label2( "NoInput:" ), Child, ti2 = TextinputObject, TextFrame, MUIA_Background, MUII_TextBack, MUIA_Textinput_NoInput, TRUE, MUIA_Textinput_Contents, C1, End, End, End, Child, VGroup, GroupFrameT( "Multi line with scroll" ), Child, timl1 = TextinputscrollObject, StringFrame, MUIA_CycleChain, 1, MUIA_ControlChar, 'b', MUIA_Textinput_Multiline, TRUE, MUIA_Textinput_Contents, C2, End, Child, bt_get = SimpleButton( "Get contents (to shell window)" ), End, Child, HGroup, GroupFrameT( "NoInput multi line with Scroll" ), Child, timl2 = TextinputscrollObject, TextFrame, MUIA_Background,MUII_TextBack,MUIA_CycleChain, 1, MUIA_ControlChar, 'c', MUIA_Textinput_NoInput, TRUE, MUIA_Textinput_Multiline, TRUE, MUIA_Textinput_AutoExpand, TRUE, MUIA_Textinput_Contents, C2, MUIA_Textinput_MinVersion, 12, MUIA_Textinput_WordWrap, 60, End, End, Child, HGroup, GroupFrameT( "Old stringgadget" ), Child, String( C1, 256 ), End, End, End, End ) { DoMethod( win, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit ); DoMethod( bt_get, MUIM_Notify, MUIA_Pressed, FALSE, app, 2, MUIM_Application_ReturnID, 2 ); DoMethod( ti1, MUIM_Notify, MUIA_String_Contents, MUIV_EveryTime, ti2, 3, MUIM_Set, MUIA_Text_Contents, MUIV_TriggerValue ); DoMethod( timl1, MUIM_Notify, MUIA_String_Contents, MUIV_EveryTime, timl2, 3, MUIM_Set, MUIA_Text_Contents, MUIV_TriggerValue ); DoMethod( ti1, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime, ti1, 3, MUIM_Set, MUIA_Textinput_Contents, "" ); set( win, MUIA_Window_Open, TRUE ); while( !Done ) { LONG id; id = DoMethod( app, MUIM_Application_Input, &sig ); switch( id ) { case MUIV_Application_ReturnID_Quit: Done = TRUE; case 2: { char *p; get( timl1, MUIA_Textinput_Contents, &p ); PutStr( ">>>>>\n" ); PutStr( p ); PutStr( "<<<<<\n" ); } break; } if( sig ) if( Wait( sig | SIGBREAKF_CTRL_C ) & SIGBREAKF_CTRL_C ) Done = TRUE; } MUI_DisposeObject( app ); } CloseLibrary( MUIMasterBase ); }