public void computeStressFunction(tuple tup) { if (elemDim != 2) { return; } for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { tup.H[i, j] = 0; for (int k = 0; k < nNode; k++) { tup.H[i, j] -= phi[k] * tup.d2[i, j][k]; } } } for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { for (int l = 0; l < nNode; l++) { tup.H[i, j] += tup.Gammaijk[i, j, k] * tup.d1[k][l] * phi[l]; } } } } }
public void computeTangent(tuple tup, double a, double b, double c, double d) { if (elemDim != 2) { return; } if (tup.dcdt == null) { return; } if (tup.dcdt.Count() != 2) { return; } tup.dcdtstar[0] = tup.dcdt[1]; tup.dcdtstar[1] = -tup.dcdt[0]; double gamma = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { gamma += tup.dcdt[i] * tup.gij[i, j] * tup.dcdt[j]; } } double ax = -a / c, ay = -b / c; tup.va[0] = ax * tup.gi[0][0] + ay * tup.gi[0][1]; tup.va[1] = ax * tup.gi[1][0] + ay * tup.gi[1][1]; tup.valDc = 0; /*for (int i = 0; i < 2; i++) * { * for (int j = 0; j < 2; j++) * { * tup.valDc += tup.va[i] * tup.Gij[i, j] * tup.dcdtstar[j]; * } * }*/ tup.valDc += tup.va[0] * tup.gij[1, 1] * tup.dcdtstar[0]; tup.valDc += tup.va[1] * tup.gij[0, 0] * tup.dcdtstar[1]; tup.valDc -= tup.va[0] * tup.gij[1, 0] * tup.dcdtstar[1]; tup.valDc -= tup.va[1] * tup.gij[0, 1] * tup.dcdtstar[0]; if (tup.refDv < 0.0000001) { if (tup.gij[1, 1] > 0.0000001) { tup.valDc /= Math.Sqrt(tup.gij[1, 1]); } if (tup.gij[0, 0] > 0.0000001) { tup.valDc /= Math.Sqrt(tup.gij[0, 0]); } } else { tup.valDc /= tup.refDv; } tup.valDc /= Math.Sqrt(gamma); }
/* public static Tuple<int, int,double,double,double> calculator(int a, int b) * { * return new Tuple<int,int,double,double,double>((a + b), (a - b),(a*b),(a/b),(a%b)); * }*/ static void Main() { // Tuple<int, int, double, double,double> o = Program.calculator(10,2); // Console.WriteLine("addition=" + o.Item1 + "\nsubraction =" + o.Item2+"\nmul ="+o.Item3+"\ndiv ="+o.Item4+"\nmod ="+o.Item5); Tuple <int, int, int, int, int, int, int, int> tuple = new tuple <int, int, int, int, int, int, int, int>(1, 2, 3, 4, 5, 6, 7, 8); Console.ReadLine(); }
public void computeTangent(tuple tup) { ///below is somehow suspicious code if (elemDim != 2) { return; } if (tup.dcdt == null) { return; } if (tup.dcdt.Count() != 2) { return; } double Z = 0; /*for (int i = 0; i < nDV; i++) * { * Z += tup.shape[2, i] * node[i]; * }*/ for (int i = 0; i < nNode; i++) { Z += tup.d0[i] * phi[i]; } tup.z = Z; tup.dcdtstar[0] = tup.dcdt[1]; tup.dcdtstar[1] = -tup.dcdt[0]; double gamma = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { gamma += tup.dcdt[i] * tup.gij[i, j] * tup.dcdt[j]; } } for (int i = 0; i < 2; i++) { tup.s[i] = 0; for (int k = 0; k < nNode; k++) { tup.s[i] += tup.d1[i][k] * phi[k]; } } tup.valD = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { tup.valD += tup.s[i] * tup.Gij[i, j] * tup.dcdtstar[j]; } } tup.valD *= tup.refDv; tup.valD /= Math.Sqrt(gamma); }
public void computeGradTangent(tuple tup) { if (tup.gradD == null) { tup.gradD = new double[nDV / 3]; } if (elemDim != 2) { return; } if (tup.dcdt == null) { return; } if (tup.dcdt.Count() != 2) { return; } tup.dcdtstar[0] = tup.dcdt[1]; tup.dcdtstar[1] = -tup.dcdt[0]; double gamma = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { gamma += tup.dcdt[i] * tup.gij[i, j] * tup.dcdt[j]; } } for (int n = 0; n < nDV / 3; n++) { for (int i = 0; i < 2; i++) { tup.s[i] = tup.d1[i][n]; } var _valD = 0d; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { _valD += tup.s[i] * tup.Gij[i, j] * tup.dcdtstar[j]; } } _valD *= tup.refDv; _valD /= Math.Sqrt(gamma); tup.gradD[n] = _valD; } }
public tuple returnMaxKey() { // returns the maximum key in the tree tuple themax = new tuple(); element current; current = root; while (current.right != leaf) // search to bottom-right corner of tree { current = current.right; } // themax.m = current.stored; // store the data found themax.i = current.key; // themax.j = current.key; // return(themax); // return that data }
public void computeTangent(tuple tup) { ///below is somehow suspicious code if (elemDim != 2) return; if (tup.dcdt == null) return; if (tup.dcdt.Count() != 2) return; double Z = 0; /*for (int i = 0; i < nDV; i++) { Z += tup.shape[2, i] * node[i]; }*/ for (int i = 0; i < nNode; i++) { Z += tup.d0[i] * phi[i]; } tup.z = Z; tup.dcdtstar[0] = tup.dcdt[1]; tup.dcdtstar[1] = -tup.dcdt[0]; double gamma = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { gamma += tup.dcdt[i] * tup.gij[i, j] * tup.dcdt[j]; } } for (int i = 0; i < 2; i++) { tup.s[i] = 0; for (int k = 0; k < nNode; k++) { tup.s[i] += tup.d1[i][k] * phi[k]; } } tup.valD = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { tup.valD += tup.s[i] * tup.Gij[i, j] * tup.dcdtstar[j]; } } tup.valD *= tup.refDv; tup.valD /= Math.Sqrt(gamma); }
public void computeGradTangent(tuple tup) { if (tup.gradD == null) tup.gradD = new double[nDV / 3]; if (elemDim != 2) return; if (tup.dcdt == null) return; if (tup.dcdt.Count() != 2) return; tup.dcdtstar[0] = tup.dcdt[1]; tup.dcdtstar[1] = -tup.dcdt[0]; double gamma = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { gamma += tup.dcdt[i] * tup.gij[i, j] * tup.dcdt[j]; } } for (int n = 0; n < nDV / 3; n++) { for (int i = 0; i < 2; i++) { tup.s[i] = tup.d1[i][n]; } var _valD = 0d; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { _valD += tup.s[i] * tup.Gij[i, j] * tup.dcdtstar[j]; } } _valD *= tup.refDv; _valD /= Math.Sqrt(gamma); tup.gradD[n] = _valD; } }
public void computeStressFunction(tuple tup) { if (elemDim != 2) return; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { tup.H[i, j] = 0; for (int k = 0; k < nNode; k++) { tup.H[i, j] -= phi[k] * tup.d2[i, j][k]; } } } for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { for (int l = 0; l < nNode; l++) { tup.H[i, j] += tup.Gammaijk[i, j, k] * tup.d1[k][l] * phi[l]; } } } } }
private void ParsePidf(byte[] pidfContent) { presence presence; using (MemoryStream stream = new MemoryStream(pidfContent)) { XmlSerializer serializer = new XmlSerializer(typeof(presence)); presence = serializer.Deserialize(stream) as presence; } PresenceStatus status = PresenceStatus.Offline; if (presence != null) { person[] persons = presence.Persons; person person = null; if (persons != null) { if (persons.Length > 0) { person = persons[0]; } DateTime lastTimeStamp = DateTime.MinValue; foreach (person p in persons) { String timeStamp = p.GetTimeStamp(); if (!String.IsNullOrEmpty(timeStamp)) { DateTime timestamp = Rfc3339DateTime.Parse(timeStamp); if (timestamp.CompareTo(lastTimeStamp) > 0) { lastTimeStamp = timestamp; person = p; } } } } String statusicon = (person != null && person.statusicon != null) ? person.statusicon.Value : null; Contact contact = this.contactService.ContactFind(presence.entity); if (contact != null) { if (person != null) { // // Basic // if (person.overridingWillingness != null) { status = (person.overridingWillingness.basic == basicType.closed) ? PresenceStatus.Offline : PresenceStatus.Online; if (!String.IsNullOrEmpty(person.overridingWillingness.Until)) { contact.HyperAvaiability = Rfc3339DateTime.Parse(person.overridingWillingness.Until).ToLocalTime(); } } // // Activities // if (person.activities != null && person.activities.ItemsElementName != null) { if (person.activities.ItemsElementName.Length > 0) { switch (person.activities.ItemsElementName[0]) { case BogheCore.Generated.rpid.ItemsChoiceType.away: case BogheCore.Generated.rpid.ItemsChoiceType.shopping: case BogheCore.Generated.rpid.ItemsChoiceType.sleeping: case BogheCore.Generated.rpid.ItemsChoiceType.working: case BogheCore.Generated.rpid.ItemsChoiceType.appointment: status = PresenceStatus.Away; break; case BogheCore.Generated.rpid.ItemsChoiceType.busy: status = PresenceStatus.Busy; break; case BogheCore.Generated.rpid.ItemsChoiceType.vacation: status = PresenceStatus.BeRightBack; break; case BogheCore.Generated.rpid.ItemsChoiceType.onthephone: case BogheCore.Generated.rpid.ItemsChoiceType.playing: status = PresenceStatus.OnThePhone; break; case BogheCore.Generated.rpid.ItemsChoiceType.dinner: case BogheCore.Generated.rpid.ItemsChoiceType.breakfast: case BogheCore.Generated.rpid.ItemsChoiceType.meal: status = PresenceStatus.OutToLunch; break; } } } // Assign status contact.PresenceStatus = status; // Free Text String note = person.GetNote(); if (!String.IsNullOrEmpty(note)) { contact.FreeText = note; } // Avatar /*if (!String.IsNullOrEmpty(statusicon)) * { * contact.Avatar = this.GetContactStatusIcon(statusicon); * }*/ // Home Page String hp = person.homepage; if (!String.IsNullOrEmpty(hp)) { contact.HomePage = hp; } // Service willingness (open/closed) // IMPORTANT: ignore availability[service.status] /*if (presence.tuple != null && presence.tuple.Length > 0) * { * foreach (tuple service in presence.tuple) * { * if (service != null && service.willingness != null && service.serviceDescription != null) * { * if (service.willingness.basic == basicType.closed) * { * contact.AddClosedServices(service.serviceDescription.serviceid); * } * else if (contact.ClosedServices.Contains(service.serviceDescription.serviceid)) * { * contact.RemoveClosedServices(service.serviceDescription.serviceid); * } * } * } * }*/ } else { // Get the first tuple tuple tuple = (presence.tuple != null && presence.tuple.Length > 0) ? presence.tuple[0] : null; contact.PresenceStatus = (tuple != null && tuple.status != null && tuple.status.basic == basic.open) ? PresenceStatus.Online : PresenceStatus.Offline; } } } }
public void compute(tuple tup) { //Global position double X = 0, Y = 0, Z = 0; for (int i = 0; i < nDV; i++) { X += tup.shape[0, i] * node[i]; Y += tup.shape[1, i] * node[i]; Z += tup.shape[2, i] * node[i]; } tup.x = X; tup.y = Y; tup.z = Z; //covariant base vectors for (int n = 0; n < elemDim; n++) { double fx = 0, fy = 0; for (int i = 0; i < nDV; i++) { fx += tup.C[n, 0, i] * node[i]; fy += tup.C[n, 1, i] * node[i]; } tup.gi[n][0] = fx; tup.gi[n][1] = fy; tup.gi[n][2] = 0; } for (int n = 0; n < elemDim; n++) { for (int m = 0; m < elemDim; m++) { tup.gij[n, m] = tup.gi[n][0] * tup.gi[m][0] + tup.gi[n][1] * tup.gi[m][1] + tup.gi[n][2] * tup.gi[m][2]; } } if (elemDim == 1) { _inv1(tup.gij, tup.Gij); } else if (elemDim == 2) { _inv2(tup.gij, tup.Gij); } else if (elemDim == 3) { _inv3(tup.gij, tup.Gij); } if (elemDim == 1) { tup.dv = Math.Sqrt(_det1(tup.gij)); } else if (elemDim == 2) { tup.dv = Math.Sqrt(_det2(tup.gij)); } else if (elemDim == 3) { tup.dv = Math.Sqrt(_det3(tup.gij)); } tup.refDv = tup.dv; //contravatiant base vectors for (int n = 0; n < elemDim; n++) { double Fx = 0, Fy = 0; for (int m = 0; m < elemDim; m++) { Fx += tup.gi[m][0] * tup.Gij[m, n]; Fy += tup.gi[m][1] * tup.Gij[m, n]; } tup.Gi[n][0] = Fx; tup.Gi[n][1] = Fy; tup.Gi[n][2] = 0; } //Connection coefficients for (int n = 0; n < elemDim; n++) { for (int m = 0; m < elemDim; m++) { double gx = 0, gy = 0; for (int i = 0; i < nDV; i++) { gx += tup.D[n, m, 0, i] * node[i]; gy += tup.D[n, m, 1, i] * node[i]; } tup.second[n, m][0] = gx; tup.second[n, m][1] = gy; tup.second[n, m][2] = 0; for (int k = 0; k < elemDim; k++) { tup.Gammaijk[n, m, k] = gx * tup.Gi[k][0] + gy * tup.Gi[k][1]; } } } //Create gradient of hessian with computed connection coefficients for (int m = 0; m < elemDim; m++) { for (int n = 0; n < elemDim; n++) { for (int k = 0; k < nNode; k++) { tup.d2[m, n][k] = tup.D[m, n, 2, k * __DIM + 2]; /*for (int i = 0; i < elemDim; i++) { gradient[m, n][k] -= Gamma[m, n, i] * C[i, 2, k * 3 + 2]; }*/ } } } for (int m = 0; m < elemDim; m++) { for (int k = 0; k < nNode; k++) { tup.d1[m][k] = tup.C[m, 2, k * __DIM + 2]; } } for (int k = 0; k < nNode; k++) { tup.d0[k] = tup.shape[2, k * __DIM + 2]; } }
/// <summary> /// Undo /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button3_Click(object sender, EventArgs e) { if (flag == true) { return; } int fail = 0; if (Count == 0) // phương án dự phòng nhưng có vẻ không dùng đến . { Invoke(new ShowMessageDelegate(ShowMessage), " Không thể undo !\n Hoặc đã sử dụng quyền trợ giúp Redo , redo xong không thể tiếp tục Undo cho đến khi đi nước mới !", "Thông báo" , MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (Count == 1) { Invoke(new ShowMessageDelegate(ShowMessage), "Không thể load form đã Undo trước đó !\n\nHoặc vì đã sử dụng Undo để đi nước cờ mới !", "Thông báo" , MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //if (Save_Board.Count==0) //{ // Invoke(new ShowMessageDelegate(ShowMessage), " Không thể undo tiếp !\n Hoặc đã sử dụng quyền trợ giúp Redo , redo xong không thể tiếp tục Undo cho đến khi đi nước mới !", "Thông báo" // , MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} //if (Save_Board.Count == 1) //{ // Invoke(new ShowMessageDelegate(ShowMessage), "Sau khi Undo để đi nước cờ mới không thể Undo lại ", "Thông báo" // , MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} //try //{ helped = 1; fail = 1; panelColor.BackColor = Color.Black; label26.Text = "LƯỢT BẠN"; Board p = Save_Board[Count - 2]; board.Copy(p); tuple p1 = Save_Point[Count - 2]; Count--; board.X_Pre = p1.x; board.Y_Pre = p1.y; board.Draw(panel1, IsDrawHelp, Board.BLACK); ShowPoints(); int valueboard = board.GetValue(); Invoke(new InvokeShowGrade(ShowGrade), valueboard.ToString()); Invoke(new EnableTimerDelegate(EnableTimer), false); string Undoed = "Đã Undo "; ListViewItem Undo_ListViewItem = new ListViewItem(Undoed); listView1.Items.Add(Undo_ListViewItem); listView1.EnsureVisible(listView1.Items.Count - 1); bugcuoicung = 0; //} //catch //{ // helped = 1; // fail = 1; // panelColor.BackColor = Color.Black; // label26.Text = "LƯỢT BẠN"; // Board p = Save_Board[0]; // board.Copy(p); // tuple p1 = Save_Point[0]; // Count--; // board.X_Pre = p1.x; // board.Y_Pre = p1.y; // board.Draw(panel1, IsDrawHelp, Board.BLACK); // ShowPoints(); // int valueboard = board.GetValue(); // Invoke(new InvokeShowGrade(ShowGrade), valueboard.ToString()); // Invoke(new EnableTimerDelegate(EnableTimer), false); // string Undoed = "Đã Undo "; // ListViewItem Undo_ListViewItem = new ListViewItem(Undoed); // listView1.Items.Add(Undo_ListViewItem); // listView1.EnsureVisible(listView1.Items.Count -1); // bugcuoicung = 0; //} if (fail == 0) { Invoke(new ShowMessageDelegate(ShowMessage), " Không thể undo tiếp !", "Thông báo" , MessageBoxButtons.OK, MessageBoxIcon.Information); return; } }
public integer getWays(integer N, tuple (integer)colors)
_databaseService.DB.Insert(new InstalledModEntry(tuple, fileChanges, date));
// points foundNode at the corresponding node public void insertItem(int newKey, double newStored) { // insert a new key with stored value // first we check to see if newKey is already present in the tree; if so, we simply // set .stored += newStored; if not, we must find where to insert the key element newNode, current; newNode = new element(); current = findItem(newKey); // find newKey in tree; return pointer to it O(log k) if (current != null) { current.stored += newStored; // update its stored value heap.updateItemdub(current.heap_ptr, current.stored); // update corresponding element in heap + reheapify; O(log k) } else { // didn't find it, so need to create it tuple newitem = new tuple(); // newitem.m = newStored; // newitem.i = -1; // newitem.j = newKey; // //newNode = new element; // element for the vektor newNode.key = newKey; // store newKey newNode.stored = newStored; // store newStored newNode.color = true; // new nodes are always RED newNode.parent = null; // new node initially has no parent newNode.left = leaf; // left leaf newNode.right = leaf; // right leaf newNode.heap_ptr = heap.insertItem(newitem); // add new item to the vektor heap support++; // increment node count in vektor // must now search for where to insert newNode, i.e., find the correct parent and // set the parent and child to point to each other properly current = root; if (current.key==0) { // insert as root // delete old root root = newNode; // set root to newNode leaf.parent = newNode; // set leaf's parent current = leaf; // skip next loop } while (current != leaf) { // search for insertion point if (newKey < current.key) { // left-or-right? if (current.left != leaf) { current = current.left; } // try moving down-left else { // else found new parent newNode.parent = current; // set parent current.left = newNode; // set child current = leaf; // exit search } } else { // if (current.right != leaf) { current = current.right; } // try moving down-right else { // else found new parent newNode.parent = current; // set parent current.right = newNode; // set child current = leaf; // exit search } } } // now do the house-keeping necessary to preserve the red-black properties insertCleanup(newNode); // do house-keeping to maintain balance } return; }
public void deleteItem(int killKey) // selete a node with given key { element x, y, z; z = findItem(killKey); if (z == null) { return; } // item not present; bail out if (z != null) { tuple newmax = heap.returnMaximum(); // get old maximum in O(1) heap.deleteItem(z.heap_ptr); // delete item in the max-heap O(log k) } if (support == 1) // -- attempt to delete the root { root.key = 0; // restore root node to default state root.stored = -4294967296.0; // root.color = false; // root.parent = null; // root.left = leaf; // root.right = leaf; // root.heap_ptr.enabled = false; // support--; // set support to zero return; // exit - no more work to do } if (z != null) { support--; // decrement node count if ((z.left == leaf) || (z.right == leaf)) // case of less than two children { y = z; } // set y to be z else { y = returnSuccessor(z); } // set y to be z's key-successor if (y.left != leaf) { x = y.left; } // pick y's one child (left-child) else { x = y.right; } // (right-child) x.parent = y.parent; // make y's child's parent be y's parent if (y.parent == null) { root = x; } // if y is the root, x is now root else // { if (y == y.parent.left) // decide y's relationship with y's parent { y.parent.left = x; // replace x as y's parent's left child } else // { y.parent.right = x; } // replace x as y's parent's left child } // if (y != z) // insert y into z's spot { z.key = y.key; // copy y data into z z.stored = y.stored; // z.heap_ptr = y.heap_ptr; // } // if (y.color == false) { deleteCleanup(x); } // do house-keeping to maintain balance // deallocate y y = null; // point y to NULL for safety } // return; }
// ------------------------------------------------------------------------------------ // // ------------------------------------------------------------------------------------ // // ------------------------------------------------------------------------------------ // // FUNCTION DEFINITIONS --------------------------------------------------------------- // void buildDeltaQMatrix() { // Given that we've now populated a sparse (unordered) adjacency matrix e (e), // we now need to construct the intial dQ matrix according to the definition of dQ // which may be derived from the definition of modularity Q: // Q(t) = \sum_{i} (e_{ii} - a_{i}^2) = Tr(e) - ||e^2|| // thus dQ is // dQ_{i,j} = 2* ( e_{i,j} - a_{i}a_{j} ) // where a_{i} = \sum_{j} e_{i,j} (i.e., the sum over the ith row) // To create dQ, we must insert each value of dQ_{i,j} into a binary search tree, // for the jth column. That is, dQ is simply an array of such binary search trees, // each of which represents the dQ_{x,j} adjacency vector. Having created dQ as // such, we may happily delete the matrix e in order to free up more memory. // The next step is to create a max-heap data structure, which contains the entries // of the following form (value, s, t), where the heap-key is 'value'. Accessing the // root of the heap gives us the next dQ value, and the indices (s,t) of the vectors // in dQ which need to be updated as a result of the merge. // First we compute e_{i,j}, and the compute+store the a_{i} values. These will be used // shortly when we compute each dQ_{i,j}. edge current; double eij = (double)(0.5 / gparm.m); // intially each e_{i,j} = 1/m for (int i = 1; i < gparm.maxid; i++) { // for each row if (e[i].so != 0) { // ensure it exists current = e[i]; // grab first edge a[i] = eij; // initialize a[i] while (current.next != null) { // loop through remaining edges a[i] += eij; // add another eij current = current.next; // } Q[0] += -1.0 * a[i] * a[i]; // calculate initial value of Q } } // now we create an empty (ordered) sparse matrix dq[] dq = new nodenub[gparm.maxid]; // initialize dq matrix for (int i = 0; i < gparm.maxid; i++) { // //dq[i].heap_ptr; // no pointer in the heap at first if (e[i].so != 0) { dq[i].v = new vektor(2 + (int)(gparm.m * a[i])); } else { dq[i].v = null; } } h = new modmaxheap(gparm.n); // allocate max-heap of size = number of nodes // Now we do all the work, which happens as we compute and insert each dQ_{i,j} into // the corresponding (ordered) sparse vector dq[i]. While computing each dQ for a // row i, we track the maximum dQmax of the row and its (row,col) indices (i,j). Upon // finishing all dQ's for a row, we insert the tuple into the max-heap hQmax. That // insertion returns the itemaddress, which we then store in the nodenub heap_ptr for // that row's vector. double dQ; tuple dQmax = new tuple(); // for heaping the row maxes //tuple itemaddress; // stores address of item in maxheap for (int i = 1; i < gparm.maxid; i++) { if (e[i].so != 0) { current = e[i]; // grab first edge dQ = 2.0 * (eij - (a[current.so] * a[current.si])); // compute its dQ dQmax.m = dQ; // assume it is maximum so far dQmax.i = current.so; // store its (row,col) dQmax.j = current.si; // dQmax.enabled = true; dq[i].v.insertItem(current.si, dQ); // insert its dQ while (current.next != null) { // current = current.next; // step to next edge dQ = 2.0 * (eij - (a[current.so] * a[current.si])); // compute new dQ if (dQ > dQmax.m) { // if dQ larger than current max dQmax.m = dQ; // replace it as maximum so far dQmax.j = current.si; // and store its (col) } dq[i].v.insertItem(current.si, dQ); // insert it into vector[i] } dq[i].heap_ptr = h.insertItem(dQmax); // store the pointer to its loc in heap } } e = null; elist = null; // free-up adjacency matrix memory in two shots // return; }
// points foundNode at the corresponding node public void insertItem(int newKey, double newStored)// insert a new key with stored value // first we check to see if newKey is already present in the tree; if so, we simply // set .stored += newStored; if not, we must find where to insert the key { element newNode, current; newNode = new element(); current = findItem(newKey); // find newKey in tree; return pointer to it O(log k) if (current != null) { current.stored += newStored; // update its stored value heap.updateItemdub(current.heap_ptr, current.stored); // update corresponding element in heap + reheapify; O(log k) } else // didn't find it, so need to create it { tuple newitem = new tuple(); // newitem.m = newStored; // newitem.i = -1; // newitem.j = newKey; // //newNode = new element; // element for the vektor newNode.key = newKey; // store newKey newNode.stored = newStored; // store newStored newNode.color = true; // new nodes are always RED newNode.parent = null; // new node initially has no parent newNode.left = leaf; // left leaf newNode.right = leaf; // right leaf newNode.heap_ptr = heap.insertItem(newitem); // add new item to the vektor heap support++; // increment node count in vektor // must now search for where to insert newNode, i.e., find the correct parent and // set the parent and child to point to each other properly current = root; if (current.key == 0) // insert as root // delete old root { root = newNode; // set root to newNode leaf.parent = newNode; // set leaf's parent current = leaf; // skip next loop } while (current != leaf) // search for insertion point { if (newKey < current.key) // left-or-right? { if (current.left != leaf) { current = current.left; } // try moving down-left else // else found new parent { newNode.parent = current; // set parent current.left = newNode; // set child current = leaf; // exit search } } else // { if (current.right != leaf) { current = current.right; } // try moving down-right else // else found new parent { newNode.parent = current; // set parent current.right = newNode; // set child current = leaf; // exit search } } } // now do the house-keeping necessary to preserve the red-black properties insertCleanup(newNode); // do house-keeping to maintain balance } return; }
public void compute(tuple tup) { //Global position double X = 0, Y = 0, Z = 0; for (int i = 0; i < nDV; i++) { X += tup.shape[0, i] * node[i]; Y += tup.shape[1, i] * node[i]; Z += tup.shape[2, i] * node[i]; } tup.x = X; tup.y = Y; tup.z = Z; //covariant base vectors for (int n = 0; n < elemDim; n++) { double fx = 0, fy = 0; for (int i = 0; i < nDV; i++) { fx += tup.C[n, 0, i] * node[i]; fy += tup.C[n, 1, i] * node[i]; } tup.gi[n][0] = fx; tup.gi[n][1] = fy; tup.gi[n][2] = 0; } for (int n = 0; n < elemDim; n++) { for (int m = 0; m < elemDim; m++) { tup.gij[n, m] = tup.gi[n][0] * tup.gi[m][0] + tup.gi[n][1] * tup.gi[m][1] + tup.gi[n][2] * tup.gi[m][2]; } } if (elemDim == 1) { _inv1(tup.gij, tup.Gij); } else if (elemDim == 2) { _inv2(tup.gij, tup.Gij); } else if (elemDim == 3) { _inv3(tup.gij, tup.Gij); } if (elemDim == 1) { tup.dv = Math.Sqrt(_det1(tup.gij)); } else if (elemDim == 2) { tup.dv = Math.Sqrt(_det2(tup.gij)); } else if (elemDim == 3) { tup.dv = Math.Sqrt(_det3(tup.gij)); } tup.refDv = tup.dv; //contravatiant base vectors for (int n = 0; n < elemDim; n++) { double Fx = 0, Fy = 0; for (int m = 0; m < elemDim; m++) { Fx += tup.gi[m][0] * tup.Gij[m, n]; Fy += tup.gi[m][1] * tup.Gij[m, n]; } tup.Gi[n][0] = Fx; tup.Gi[n][1] = Fy; tup.Gi[n][2] = 0; } //Connection coefficients for (int n = 0; n < elemDim; n++) { for (int m = 0; m < elemDim; m++) { double gx = 0, gy = 0; for (int i = 0; i < nDV; i++) { gx += tup.D[n, m, 0, i] * node[i]; gy += tup.D[n, m, 1, i] * node[i]; } tup.second[n, m][0] = gx; tup.second[n, m][1] = gy; tup.second[n, m][2] = 0; for (int k = 0; k < elemDim; k++) { tup.Gammaijk[n, m, k] = gx * tup.Gi[k][0] + gy * tup.Gi[k][1]; } } } //Create gradient of hessian with computed connection coefficients for (int m = 0; m < elemDim; m++) { for (int n = 0; n < elemDim; n++) { for (int k = 0; k < nNode; k++) { tup.d2[m, n][k] = tup.D[m, n, 2, k *__DIM + 2]; /*for (int i = 0; i < elemDim; i++) * { * gradient[m, n][k] -= Gamma[m, n, i] * C[i, 2, k * 3 + 2]; * }*/ } } } for (int m = 0; m < elemDim; m++) { for (int k = 0; k < nNode; k++) { tup.d1[m][k] = tup.C[m, 2, k *__DIM + 2]; } } for (int k = 0; k < nNode; k++) { tup.d0[k] = tup.shape[2, k *__DIM + 2]; } }
public void precompute(tuple tup) { //Assume M[0] and M[1] are precomputed, //double[][,] M=new double[2][,]; //M[0]=fM(uNum,_uDim,_uDim-1,uKnot); //M[1]=fM(vNum,_vDim,_vDim-1,vKnot); tup.internalIndex = this.index; tup.nNode = nDV / 3; tup.elemDim = elemDim; tup.shape = new double[__DIM, nDV]; //Global coordinate *coefficient* tup.C = new double[elemDim, __DIM, nDV]; //Base vectors *coefficient* tup.B = new double[elemDim, elemDim, nDV, nDV]; //Metric *coefficient* tup.D = new double[elemDim, elemDim, __DIM, nDV]; //Hessian coefficient tup.d0 = new double[nDV / 3]; tup.d1 = new double[elemDim][]; tup.d2 = new double[elemDim, elemDim][]; for (int i = 0; i < elemDim; i++) { tup.d1[i] = new double[nDV / 3]; } for (int i = 0; i < elemDim; i++) { for (int j = 0; j < elemDim; j++) { tup.d2[i, j] = new double[nDV / 3]; } } //Shape functions [N] (for global coordinate) for (int j = 0; j < elemDim; j++) { double t = tup.lo[j]; for (int k = 0; k < dim[j]; k++) { hh[j][k] = Math.Pow(t, (dim[j] - k - 1)); } for (int k = 0; k < dim[j]; k++) { double val = 0; for (int l = 0; l < dim[j]; l++) { val += hh[j][l] * M[j][l, k]; } tt[j][k] = val; } } for (int j = 0; j < __DIM; j++) { for (int k = 0; k < nDV; k++) { tup.shape[j, k] = 0; } } for (int k = 0; k < nNode; k++) { //Shape functinos double shape = 1.0; for (int j = 0; j < elemDim; j++) { shape *= tt[j][dd[k, j]]; } for (int j = 0; j < __DIM; j++) { tup.shape[j, k *__DIM + j] = shape; } } //Create [C] (for base vectors) for (int m = 0; m < elemDim; m++) { for (int j = 0; j < elemDim; j++) { double t = tup.lo[j]; if (j != m) { for (int k = 0; k < dim[j]; k++) { hh[j][k] = Math.Pow(t, (dim[j] - k - 1)); } } else { for (int k = 0; k < dim[j] - 1; k++) { hh[j][k] = (dim[j] - k - 1) * Math.Pow(t, (dim[j] - k - 2)); } hh[j][dim[j] - 1] = 0; } for (int k = 0; k < dim[j]; k++) { double val = 0; for (int l = 0; l < dim[j]; l++) { val += hh[j][l] * M[j][l, k]; } tt[j][k] = val; } } for (int jj = 0; jj < __DIM; jj++) { for (int j = 0; j < nDV; j++) { tup.C[m, jj, j] = 0; } } for (int k = 0; k < nNode; k++) { //[C] double C = 1.0; for (int j = 0; j < elemDim; j++) { C *= tt[j][dd[k, j]]; } for (int j = 0; j < __DIM; j++) { tup.C[m, j, k *__DIM + j] = C; } } } //Create [B] (for metric) tup.CtoB(elemDim, nDV); //Create [D] (for second derivative) for (int m = 0; m < elemDim; m++) { for (int n = 0; n < elemDim; n++) { for (int j = 0; j < elemDim; j++) { double t = tup.lo[j]; if (j != m && j != n) { for (int k = 0; k < dim[j]; k++) { hh[j][k] = Math.Pow(t, (dim[j] - k - 1)); } } if ((j != m && j == n) || (j == m && j != n)) { for (int k = 0; k < dim[j] - 1; k++) { hh[j][k] = (dim[j] - k - 1) * Math.Pow(t, (dim[j] - k - 2)); } hh[j][dim[j] - 1] = 0; } if (j == m && j == n) { for (int k = 0; k < dim[j] - 1; k++) { hh[j][k] = (dim[j] - k - 1) * (dim[j] - k - 2) * Math.Pow(t, (dim[j] - k - 3)); } hh[j][dim[j] - 1] = 0; hh[j][dim[j] - 2] = 0; } for (int k = 0; k < dim[j]; k++) { double val = 0; for (int l = 0; l < dim[j]; l++) { val += hh[j][l] * M[j][l, k]; } tt[j][k] = val; } } for (int jj = 0; jj < __DIM; jj++) { for (int j = 0; j < nDV; j++) { tup.D[m, n, jj, j] = 0; } } for (int k = 0; k < nNode; k++) { //[D] double D = 1.0; for (int j = 0; j < elemDim; j++) { D *= tt[j][dd[k, j]]; } for (int j = 0; j < __DIM; j++) { tup.D[m, n, j, k *__DIM + j] = D; } } } } compute(tup); }
public void computeTangent(tuple tup,double a, double b, double c, double d) { if (elemDim != 2) return; if (tup.dcdt == null) return; if (tup.dcdt.Count() != 2) return; tup.dcdtstar[0] = tup.dcdt[1]; tup.dcdtstar[1] = -tup.dcdt[0]; double gamma = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { gamma += tup.dcdt[i] * tup.gij[i, j] * tup.dcdt[j]; } } double ax = -a / c, ay = -b / c; tup.va[0] = ax * tup.gi[0][0] + ay * tup.gi[0][1]; tup.va[1] = ax * tup.gi[1][0] + ay * tup.gi[1][1]; tup.valDc = 0; /*for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { tup.valDc += tup.va[i] * tup.Gij[i, j] * tup.dcdtstar[j]; } }*/ tup.valDc += tup.va[0] * tup.gij[1, 1] * tup.dcdtstar[0]; tup.valDc += tup.va[1] * tup.gij[0, 0] * tup.dcdtstar[1]; tup.valDc -= tup.va[0] * tup.gij[1, 0] * tup.dcdtstar[1]; tup.valDc -= tup.va[1] * tup.gij[0, 1] * tup.dcdtstar[0]; if (tup.refDv < 0.0000001) { if (tup.gij[1, 1] > 0.0000001) tup.valDc /= Math.Sqrt(tup.gij[1, 1]); if (tup.gij[0, 0] > 0.0000001) tup.valDc /= Math.Sqrt(tup.gij[0, 0]); } else { tup.valDc /= tup.refDv; } tup.valDc /= Math.Sqrt(gamma); }
public tuple returnMaxKey() { // returns the maximum key in the tree tuple themax = new tuple(); element current; current = root; while (current.right != leaf) { // search to bottom-right corner of tree current = current.right; } // themax.m = current.stored; // store the data found themax.i = current.key; // themax.j = current.key; // return themax; // return that data }
public void precompute(tuple tup) { //Assume M[0] and M[1] are precomputed, //double[][,] M=new double[2][,]; //M[0]=fM(uNum,_uDim,_uDim-1,uKnot); //M[1]=fM(vNum,_vDim,_vDim-1,vKnot); tup.internalIndex = this.index; tup.nNode = nDV/3; tup.elemDim = elemDim; tup.shape = new double[__DIM, nDV]; //Global coordinate *coefficient* tup.C = new double[elemDim, __DIM, nDV]; //Base vectors *coefficient* tup.B = new double[elemDim, elemDim, nDV, nDV]; //Metric *coefficient* tup.D = new double[elemDim, elemDim, __DIM, nDV]; //Hessian coefficient tup.d0 = new double[nDV/3]; tup.d1 = new double[elemDim][]; tup.d2 = new double[elemDim, elemDim][]; for (int i = 0; i < elemDim; i++) { tup.d1[i] = new double[nDV/3]; } for (int i = 0; i < elemDim; i++) { for (int j = 0; j < elemDim; j++) { tup.d2[i, j] = new double[nDV/3]; } } //Shape functions [N] (for global coordinate) for(int j=0;j<elemDim;j++) { double t=tup.lo[j]; for(int k=0;k<dim[j];k++) { hh[j][k]=Math.Pow(t,(dim[j]-k-1)); } for(int k=0;k<dim[j];k++) { double val=0; for(int l=0;l<dim[j];l++) { val+=hh[j][l]*M[j][l,k]; } tt[j][k]=val; } } for (int j = 0; j < __DIM; j++) { for (int k = 0; k < nDV; k++) { tup.shape[j, k] = 0; } } for (int k = 0; k < nNode; k++) { //Shape functinos double shape = 1.0; for (int j = 0; j < elemDim; j++) { shape *= tt[j][dd[k, j]]; } for (int j = 0; j < __DIM; j++) { tup.shape[j, k * __DIM + j] = shape; } } //Create [C] (for base vectors) for (int m = 0; m < elemDim; m++) { for (int j = 0; j < elemDim; j++) { double t = tup.lo[j]; if (j != m) { for (int k = 0; k < dim[j]; k++) { hh[j][k] = Math.Pow(t, (dim[j] - k - 1)); } } else { for (int k = 0; k < dim[j] - 1; k++) { hh[j][k] = (dim[j] - k - 1) * Math.Pow(t, (dim[j] - k - 2)); } hh[j][dim[j] - 1] = 0; } for (int k = 0; k < dim[j]; k++) { double val = 0; for (int l = 0; l < dim[j]; l++) { val += hh[j][l] * M[j][l, k]; } tt[j][k] = val; } } for (int jj = 0; jj < __DIM; jj++) { for (int j = 0; j < nDV; j++) { tup.C[m, jj, j] = 0; } } for (int k = 0; k < nNode; k++) { //[C] double C = 1.0; for (int j = 0; j < elemDim; j++) { C *= tt[j][dd[k, j]]; } for (int j = 0; j < __DIM; j++) { tup.C[m, j, k * __DIM + j] = C; } } } //Create [B] (for metric) tup.CtoB(elemDim, nDV); //Create [D] (for second derivative) for (int m = 0; m < elemDim; m++) { for (int n = 0; n < elemDim; n++) { for (int j = 0; j < elemDim; j++) { double t = tup.lo[j]; if (j != m && j != n) { for (int k = 0; k < dim[j]; k++) { hh[j][k] = Math.Pow(t, (dim[j] - k - 1)); } } if ((j != m && j == n) || (j == m && j != n)) { for (int k = 0; k < dim[j] - 1; k++) { hh[j][k] = (dim[j] - k - 1) * Math.Pow(t, (dim[j] - k - 2)); } hh[j][dim[j] - 1] = 0; } if (j == m && j == n) { for (int k = 0; k < dim[j] - 1; k++) { hh[j][k] = (dim[j] - k - 1) * (dim[j] - k - 2) * Math.Pow(t, (dim[j] - k - 3)); } hh[j][dim[j] - 1] = 0; hh[j][dim[j] - 2] = 0; } for (int k = 0; k < dim[j]; k++) { double val = 0; for (int l = 0; l < dim[j]; l++) { val += hh[j][l] * M[j][l, k]; } tt[j][k] = val; } } for (int jj = 0; jj < __DIM; jj++) { for (int j = 0; j < nDV; j++) { tup.D[m, n, jj, j] = 0; } } for (int k = 0; k < nNode; k++) { //[D] double D = 1.0; for (int j = 0; j < elemDim; j++) { D *= tt[j][dd[k, j]]; } for (int j = 0; j < __DIM; j++) { tup.D[m, n, j, k * __DIM + j] = D; } } } } compute(tup); }
/// <summary> /// Redo /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button4_Click(object sender, EventArgs e) { if (flag == true) { return; } // thực ra ở đây fail là không cần sử dụng . if (Count == Save_Board.Count) { Invoke(new ShowMessageDelegate(ShowMessage), "Không thể Redo !", "Thông báo" , MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //if (Save_Board.Count == 0) //{ // Invoke(new ShowMessageDelegate(ShowMessage), "Không thể Redo !", "Thông báo" // , MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} int fail = 0; //if (Count == 1) //{ panelColor.BackColor = Color.Black; label26.Text = "LƯỢT BẠN"; Board b = Save_Board[Count]; board.Copy(b); tuple b1 = Save_Point[Count]; Count++; board.X_Pre = b1.x; board.Y_Pre = b1.y; board.Draw(panel1, IsDrawHelp, Board.BLACK); ShowPoints(); int valueboard = board.GetValue(); Invoke(new InvokeShowGrade(ShowGrade), valueboard.ToString()); Invoke(new EnableTimerDelegate(EnableTimer), false); string Undoed = "Đã Redo"; ListViewItem Undo_ListViewItem = new ListViewItem(Undoed); listView1.Items.Add(Undo_ListViewItem); listView1.EnsureVisible(listView1.Items.Count - 1); fail = 1; bugcuoicung = 0; //} //else //{ // panelColor.BackColor = Color.Black; // label26.Text = "LƯỢT BẠN"; // Board b = Save_Board[Count ]; // board.Copy(b); // tuple b1 = Save_Point[Count ]; // Count++; // board.X_Pre = b1.x; // board.Y_Pre = b1.y; // board.Draw(panel1, IsDrawHelp, Board.BLACK); // ShowPoints(); // int valueboard = board.GetValue(); // Invoke(new InvokeShowGrade(ShowGrade), valueboard.ToString()); // Invoke(new EnableTimerDelegate(EnableTimer), false); // string Undoed = "Đã Redo"; // ListViewItem Undo_ListViewItem = new ListViewItem(Undoed); // listView1.Items.Add(Undo_ListViewItem); // listView1.EnsureVisible(listView1.Items.Count-1); // fail = 1; // bugcuoicung = 0; //} if (fail == 0) { Invoke(new ShowMessageDelegate(ShowMessage), "Không thể redo được được nữa !", "Thông báo" , MessageBoxButtons.OK, MessageBoxIcon.Information); return; } }