/// <summary> /// /// </summary> /// <param name="n"></param> /// <param name="weights"></param> /// <param name="edges"></param> /// <returns></returns> public static long CalculateMaximumProduct(int n, int[] weights, IList <Node> edges) { long maximumProduct = long.MinValue; foreach (var edge in edges) { int id1 = edge.Id1; int id2 = edge.Id2; // separate the graph to break the edge into two parts // from each node to do BFS graph search, find maximum weight sum and minimum weight sum var weightSet1 = new WeightSet(); weightSet1.ReprenstativeID = id1; var weightSet2 = new WeightSet(); weightSet2.ReprenstativeID = id2; RunBreathFirstSearch(edges, edge, id1, weights, ref weightSet1); RunBreathFirstSearch(edges, edge, id2, weights, ref weightSet2); long negativeOne = weightSet1.NegativeMinimumWeight * weightSet2.NegativeMinimumWeight; long positiveOne = weightSet1.PositiveMaximumWeight * weightSet2.PositiveMaximumWeight; maximumProduct = negativeOne > maximumProduct ? negativeOne : maximumProduct; maximumProduct = positiveOne > maximumProduct ? positiveOne : maximumProduct; } return(maximumProduct); }
private void Write(DataWriter w) { w.Write((byte)0x1A); w.Write(SerializerVersion); w.Write(PoseMatcherVersion); w.Write(Signature); w.Write(SamplesCount); if (SamplesCount > 0) { foreach (var entry in Samples) { entry.Write(w); } } w.Write(BoneTagsCount); if (BoneTagsCount > 0) { foreach (var boneTag in BoneTags) { w.Write(boneTag); } } WeightSet.Write(w); w.Write(Unk7); w.Write(Unk8); w.Write(Signature); }
public void WriteXml(StringBuilder sb, int indent) { //YpdbXml.ValueTag(sb, indent, "SerializerVersion", SerializerVersion.ToString()); //YpdbXml.ValueTag(sb, indent, "PoseMatcherVersion", PoseMatcherVersion.ToString()); YpdbXml.ValueTag(sb, indent, "Signature", Signature.ToString()); //YpdbXml.ValueTag(sb, indent, "Unk7", FloatUtil.ToString(Unk7)); //YpdbXml.ValueTag(sb, indent, "Unk8", Unk8.ToString()); YpdbXml.WriteRawArray(sb, BoneTags, indent, "BoneTags", ""); WeightSet?.WriteXml(sb, indent); YpdbXml.WriteItemArray(sb, Samples, indent, "Samples"); }
public EnemySelector() { _weightSets = new List <WeightSet>(); _standardWeightOffsets = new WeightSet(); _baseWeights = new WeightSet(); _aggregateWeights = new Dictionary <int, int>(); foreach (EnemyType enemyType in StaticData.EnemyData.EnemyTypeArray) { _baseWeights.WeightsByEnemyId.Add(enemyType.Id, enemyType.ChoiceWeight); } _weightSets.Add(_baseWeights); _weightSets.Add(_standardWeightOffsets); }
public EnemySelector() { _weightSets = new List<WeightSet>(); _standardWeightOffsets = new WeightSet(); _baseWeights = new WeightSet(); _aggregateWeights = new Dictionary<int, int>(); foreach (EnemyType enemyType in StaticData.EnemyData.EnemyTypeArray) { _baseWeights.WeightsByEnemyId.Add(enemyType.Id, enemyType.ChoiceWeight); } _weightSets.Add(_baseWeights); _weightSets.Add(_standardWeightOffsets); }
private void tsbtnUpdate_Click(object sender, EventArgs e) { try { dc = new DCQUALITYDataContext(); WeightSet ws = dc.WeightSet.Where(n => n.WeightSet_id == currentId).First(); cbxTestItem.SelectedValue = ws.WeightSet_TestItems_ID; cbxWeightNum.SelectedIndex = Convert.ToInt32(ws.WeightSet_weightNum) - 1; btnAdd.Text = "修改"; cbxTestItem.Enabled = false; LoadData(); } catch (Exception ex) { throw; } }
private void okBtn_Click(object sender, EventArgs e) { if (double.TryParse(landingFuelTxtBox.Text, out var fuel) && fuel >= 0.0) { if (acRequest.WtUnit == WeightUnit.LB) { fuel *= Constants.LbKgRatio; } LandingWtKg = acRequest.ZfwKg + fuel; Close(); WeightSet?.Invoke(this, EventArgs.Empty); } else { this.ShowWarning("The landing fuel is not valid."); } }
/// <summary> /// 添加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAdd_Click(object sender, EventArgs e) { try { WeightSet ws = new WeightSet(); dc = new DCQUALITYDataContext(); if (btnAdd.Text == "添加") { if (isHaveWeightSet(Convert.ToInt32(cbxTestItem.SelectedValue))) { ws.WeightSet_TestItems_ID = Convert.ToInt32(cbxTestItem.SelectedValue); ws.WeightSet_weightNum = cbxWeightNum.SelectedIndex + 1; dc = new DCQUALITYDataContext(); dc.WeightSet.InsertOnSubmit(ws); dc.SubmitChanges(); MessageBox.Show("操作成功!", "提示"); } else { MessageBox.Show("该检测项目已经配置,请修改或删除后再添加!"); } } else if (btnAdd.Text == "修改" && currentId > 0) { ws = dc.WeightSet.Where(n => n.WeightSet_id == currentId).First(); ws.WeightSet_TestItems_ID = Convert.ToInt32(cbxTestItem.SelectedValue); ws.WeightSet_weightNum = cbxWeightNum.SelectedIndex + 1; dc.SubmitChanges(); MessageBox.Show("操作成功!", "提示"); } btnAdd.Text = "添加"; cbxTestItem.Enabled = true; LoadData(); } catch (Exception ex) { MessageBox.Show("操作失败!", "提示"); return; } }
private void RefreshWeightSets() { lbxWeightSets.Items.Clear(); _weightSets.Clear(); var weightSetPath = Path.Combine(AutoEquipSettings.PluginFolderPath, "Weight Sets"); string[] files = Directory.GetFiles(weightSetPath, "*.xml", SearchOption.AllDirectories); int selectIndex = 0; for (int i = 0; i < files.Length; i++) { string file = files[i]; string name = Path.GetFileNameWithoutExtension(file); try { WeightSet weightSet = AutoEquipSettings.LoadWeightSetFromXML(name, XElement.Load(file)); _weightSets.Add(weightSet); lbxWeightSets.Items.Add(name); if (AutoEquipSettings.ChosenWeightSet != null && AutoEquipSettings.ChosenWeightSet.Name == weightSet.Name) { selectIndex = i; } } catch (XmlException ex) { Logging.Write("[AutoEquip]: Could not load weight set {0} - {1}", name, ex.Message); } } if (selectIndex < 0 || selectIndex >= lbxWeightSets.Items.Count) { return; } lbxWeightSets.SelectedIndex = selectIndex; }
private void importFuelBtn_Click(object sender, EventArgs e) { LandingWtKg = acRequest.LandingWeightKg; Close(); WeightSet?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Need to work on something, at least make a few points if possible /// Do not think about time complexity /// Do not think about space complexity /// Do not think about too much /// Naive solution /// Brute force, get some points first /// </summary> /// <param name="edges"></param> /// <param name="edge"></param> /// <param name="representativeId"></param> /// <param name="weightInfo"></param> public static void RunBreathFirstSearch(IList <Node> edges, Node edge, int representativeId, int[] weight, ref WeightSet weightInfo) { var rootNode = new TreeNode(representativeId); rootNode.AddWeight(weight); int idSelected = representativeId; int idNotSelcted = (edge.Id1 == idSelected) ? edge.Id2 : edge.Id1; bool touchOnce = false; do { touchOnce = false; foreach (var item in edges) { int id1 = item.Id1; int id2 = item.Id2; if (rootNode.IsInTree(id1) != rootNode.IsInTree(id2) && cannotFind(id1, id2, idNotSelcted)) { var searchId = rootNode.IsInTree(id1) ? id1 : id2; var addId = rootNode.IsInTree(id1) ? id2 : id1; rootNode.Add(searchId, addId); touchOnce = true; } } } while (touchOnce); var weightsInTraverse = new HashSet <long>(); rootNode.CalculateMaximumWeightEstimated(rootNode, weightsInTraverse, 0); weightInfo.PositiveMaximumWeight = getPostiveMaximum(weightsInTraverse); weightInfo.NegativeMinimumWeight = getNegativeMaximum(weightsInTraverse); }
public void AddWeightSet(WeightSet weightSet) { _weightSets.Add(weightSet); }
public static void LoadDefaultSet() { string defaultSetsPath = Path.Combine(PluginFolderPath, "AutoEquipSetDefaults.xml"); if (!File.Exists(defaultSetsPath)) { return; } if (ObjectManager.Me == null) { return; } var myGUID = ObjectManager.Me.Guid; XElement elm = XElement.Load(defaultSetsPath); XElement[] chars = elm.Elements("Char").ToArray(); foreach (XElement cha in chars) { var guid = cha.Attributes("Guid").ToList(); if (guid.Count <= 0) { continue; } ulong guidVal; if (!ulong.TryParse(guid[0].Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out guidVal)) { continue; } if (guidVal != myGUID) { continue; } var set = cha.Attributes("Set").ToList(); if (set.Count <= 0) { continue; } string setName = set[0].Value; string pathToWeightSet = Path.Combine(PluginFolderPath, "Weight Sets\\" + setName + ".xml"); if (!File.Exists(pathToWeightSet)) { continue; } try { ChosenWeightSet = LoadWeightSetFromXML(setName, XElement.Load(pathToWeightSet)); } catch (XmlException ex) { Logging.Write("[AutoEquip]: Could not load weight set {0} - {1}", setName, ex.Message); } break; } }
public bool RemoveWeightSet(WeightSet weightSet) { return(_weightSets.Remove(weightSet)); }
public void AddWeightSet(WeightSet weightSet) { _weightSets.Add(weightSet); }
public static void LoadDefaultSet() { string defaultSetsPath = Path.Combine(PluginFolderPath, "AutoEquipSetDefaults.xml"); if (!File.Exists(defaultSetsPath)) return; if (ObjectManager.Me == null) return; var myGUID = ObjectManager.Me.Guid; XElement elm = XElement.Load(defaultSetsPath); XElement[] chars = elm.Elements("Char").ToArray(); foreach (XElement cha in chars) { var guid = cha.Attributes("Guid").ToList(); if (guid.Count <= 0) continue; ulong guidVal; if (!ulong.TryParse(guid[0].Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out guidVal)) continue; if (guidVal != myGUID) continue; var set = cha.Attributes("Set").ToList(); if (set.Count <= 0) continue; string setName = set[0].Value; string pathToWeightSet = Path.Combine(PluginFolderPath, "Weight Sets\\" + setName + ".xml"); if (!File.Exists(pathToWeightSet)) continue; try { ChosenWeightSet = LoadWeightSetFromXML(setName, XElement.Load(pathToWeightSet)); } catch (XmlException ex) { Logging.Write("[AutoEquip]: Could not load weight set {0} - {1}", setName, ex.Message); } break; } }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WeightSet obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public bool RemoveWeightSet(WeightSet weightSet) { return _weightSets.Remove(weightSet); }
/// <summary> /// (re)loads settings /// </summary> public void LoadSettings(bool constructor) { _currentSpec = null; BlacklistedInventoryItems.Clear(); NextPulse = DateTime.Now + TimeSpan.FromSeconds(1); // try { base.LoadFromXML(XElement.Load(GetSettingsPath(SettingsType.Settings, UsePVP))); } catch (Exception) { } var _path = GetSettingsPath(SettingsType.Weights, UsePVP); EquipMe.Log("Loading weights from: {0}", _path); var newset = EquipMe.LoadWeightSetFromXML(_path); if (newset != null) { WeightSet_Current = newset; } else { SaveSettings(); } }