private static void Main() { Input input = new Input(); TotalModel model = new TotalModel(input); Output output = new Output(model); //const string tickers = "AAPL,GOOG,GOOGL,YHOO,TSLA,INTC,AMZN,BIDU,ORCL,MSFT,ORCL,ATVI,NVDA,GME,LNKD,NFLX"; //string json; //using (var web = new WebClient()) //{ // var url = $"http://finance.google.com/finance/info?client=ig&q=NASDAQ%3A{tickers}"; // json = web.DownloadString(url); //} ////Google adds a comment before the json for some unknown reason, so we need to remove it //json = json.Replace("//", ""); //var v = JArray.Parse(json); //foreach (var i in v) //{ // var ticker = i.SelectToken("t"); // var price = (decimal)i.SelectToken("l"); // Console.WriteLine($"{ticker} : {price}"); //} //Console.WriteLine("Press any key to exit"); //Console.Read(); }
public TotalModel NextObjectiveValue(int[] NFlip, BitArray X, TotalModel prevTotalModel, KnapsackModel model) { var totalModel = new TotalModel(); totalModel.TotalCost = prevTotalModel.TotalCost; totalModel.TotalWeight = prevTotalModel.TotalWeight; //for each changed bit in start array foreach (var bitNumber in NFlip) { if (bitNumber != 0) //stop because there is no bitNumber elements left { //if add element if (X[bitNumber - 1] == false) { totalModel.TotalCost += model.Items[bitNumber - 1].Item1; totalModel.TotalWeight += model.Items[bitNumber - 1].Item2; } //if delete element else { totalModel.TotalCost -= model.Items[bitNumber - 1].Item1; totalModel.TotalWeight -= model.Items[bitNumber - 1].Item2; } } } if (totalModel.TotalWeight > model.C) { totalModel.IsModelAppropriate = false; } return(totalModel); }
public ActionResult Index() { try { int GYM_ID = Convert.ToInt32(Session["GYM_ID"]); var Offers = db.Offers.Where(i => i.GYM_ID == GYM_ID).OrderByDescending(i => i.ID).ToList(); List <OfferTotalModel> OfferTotalModelList = new List <OfferTotalModel>(); foreach (var d in Offers) { OfferTotalModel OfferTotalModel = new OfferTotalModel(); OfferModel offerModel = new OfferModel(); TotalModel totalModel = new TotalModel(); offerModel.Discount = d.Discount; offerModel.End_Date = d.End_Date; offerModel.ID = d.ID; offerModel.Name = d.Name; offerModel.Start_Date = d.Start_Date; offerModel.Status = d.Status; totalModel.Branch = db.Branch_Wise_Offer.Where(i => i.Offer_ID == d.ID && i.Status == true).Count(); OfferTotalModel.total = totalModel; OfferTotalModel.Offer = offerModel; OfferTotalModelList.Add(OfferTotalModel); } return(View(OfferTotalModelList)); } catch (Exception ex) { return(RedirectToAction("Contact", "Home")); } }
// GET: ShoppingCart/Delete/5 public ActionResult Delete(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TotalModel oTotal = new TotalModel(); List <ItemModel> existItemLists = (List <ItemModel>)Session["itemList"]; var oProduct = existItemLists.Single(x => x.ProductID == id); if (oProduct == null) { return(HttpNotFound()); } else { existItemLists.Remove(oProduct); decimal totalVal = 0; foreach (var item in existItemLists) { totalVal = totalVal + (item.Qty * item.Rate); } oTotal.Total = totalVal; Session["itemList"] = existItemLists; Session["totModel"] = oTotal; } ShoppingCartViewModel oModel = new ShoppingCartViewModel((List <ItemModel>)Session["itemList"], (TotalModel)Session["totModel"]); return(RedirectToAction("Index", "ShoppingCart", oModel)); }
public ActionResult Index() { try { int GYM_ID = Convert.ToInt32(Session["GYM_ID"]); var Plane = db.Planes.Where(i => i.GYM_ID == GYM_ID).OrderByDescending(i => i.ID).ToList(); List <PlaneTotalModel> PlaneTotalModelList = new List <PlaneTotalModel>(); foreach (var d in Plane) { PlaneTotalModel PlaneTotalModel = new PlaneTotalModel(); PlaneModel planeModel = new PlaneModel(); TotalModel totalModel = new TotalModel(); planeModel.Name = d.Name; planeModel.Duration = d.Duration; planeModel.Duration_No = d.Duration_No; planeModel.GST = d.GST; planeModel.GYM_ID = d.GYM_ID; planeModel.ID = d.ID; planeModel.Is_Active = d.Is_Active; planeModel.Worth = d.Worth; totalModel.Branch = db.Branch_Wise_Plane.Where(i => i.Plane_ID == d.ID && i.Status == true).Count(); PlaneTotalModel.TotalModel = totalModel; PlaneTotalModel.PlaneModel = planeModel; PlaneTotalModelList.Add(PlaneTotalModel); } return(View(PlaneTotalModelList)); } catch (Exception ex) { return(RedirectToAction("Contact", "Home")); } }
public ActionResult Index() { try { int GYM_ID = Convert.ToInt32(Session["GYM_ID"]); var Equipment = db.Equipments.Where(i => i.GYM_ID == GYM_ID).OrderByDescending(i => i.ID).ToList(); List <EquipmentTotalModel> EquipmentTotalModelList = new List <EquipmentTotalModel>(); foreach (var d in Equipment) { EquipmentTotalModel EquipmentTotalModel = new EquipmentTotalModel(); EquipmentModel EquipmentModel = new EquipmentModel(); TotalModel TotalModel = new TotalModel(); EquipmentModel.Name = d.Name; EquipmentModel.ID = d.ID; var Equipment_Number = db.Branch_Wise_Equipment.Where(i => i.Equipment_ID == d.ID && i.GYM_ID == GYM_ID).ToList(); foreach (var Equipments in Equipment_Number) { TotalModel.Equipment = TotalModel.Equipment + Convert.ToInt32(Equipments.Number); } EquipmentTotalModel.TotalModel = TotalModel; EquipmentTotalModel.EquipmentModel = EquipmentModel; EquipmentTotalModelList.Add(EquipmentTotalModel); } return(View(EquipmentTotalModelList)); } catch (Exception ex) { return(RedirectToAction("Contact", "Home")); } }
public TotalModel CalculateNewObjective(BitArray X, KnapsackModel model, double alpha) { var totalModel = new TotalModel(); for (int i = 0; i < model.N; i++) { totalModel.TotalCost += model.Items[i].Item1 * Convert.ToDouble(X[i]); totalModel.TotalWeight += model.Items[i].Item2 * Convert.ToDouble(X[i]); } totalModel.TotalCost = totalModel.TotalCost - alpha * Math.Max(totalModel.TotalWeight - model.C, 0); return(totalModel); }
public TotalModel CalculateObjectiveValue(BitArray X, KnapsackModel model) { var totalModel = new TotalModel(); for (int i = 0; i < model.N; i++) { totalModel.TotalCost += model.Items[i].Item1 * Convert.ToDouble(X[i]); totalModel.TotalWeight += model.Items[i].Item2 * Convert.ToDouble(X[i]); if (totalModel.IsModelAppropriate && totalModel.TotalWeight > model.C) { totalModel.IsModelAppropriate = false; } } return(totalModel); }
public void WriteFile(BitArray X, TotalModel model, string fileName) { StringBuilder sb = new StringBuilder(); foreach (var b in X) { sb.Append((bool)b ? "1" : "0"); } sb.ToString(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\User\Downloads\" + fileName + ".txt", true)) { file.WriteLine(sb); file.WriteLine(model.TotalCost + "\t" + model.TotalWeight); } }
public ActionResult Manager() { try { int Branvch_ID = Convert.ToInt32(Session["Branvch_ID"]); var Trainer = db.Trainers.Join(db.Branches, u => u.Branvch_ID, j => j.ID, (u, j) => new { Trainer = u, Branch = j }).Where(i => i.Branch.ID == i.Trainer.Branvch_ID && i.Trainer.Role_ID == 3 && i.Branch.ID == Branvch_ID).ToList(); List <TrainerTotalModel> TrainerTotalModelList = new List <TrainerTotalModel>(); ViewBag.Total_Student = db.Students.Where(i => i.Branch_ID == Branvch_ID).Count(); ViewBag.Total_Trainer = db.Trainers.Where(i => i.Role_ID == 3 && i.Branvch_ID == Branvch_ID).Count(); ViewBag.Today_Joining = db.Demoes.Where(d => DbFunctions.TruncateTime(d.Start_Date) == DbFunctions.TruncateTime(DateTime.Now) && d.Branch_ID == Branvch_ID).Count(); ViewBag.Student_Fee = db.Students.Where(i => i.Branch_ID == Branvch_ID && i.Status != true).Count(); ViewBag.Total_Offer = db.Branch_Wise_Offer.Where(i => i.Branch_ID == Branvch_ID && i.Status == true).Count(); ViewBag.Total_Plane = db.Branch_Wise_Plane.Where(i => i.Branch_ID == Branvch_ID && i.Status == true).Count(); foreach (var d in Trainer) { TrainerTotalModel TrainerTotalModel = new TrainerTotalModel(); TrainerModel trainerModel = new TrainerModel(); TotalModel TotalModel = new TotalModel(); trainerModel.Branvch_ID = d.Trainer.Branvch_ID; trainerModel.Email_ID = d.Trainer.Email_ID; trainerModel.First_Name = d.Trainer.First_Name; trainerModel.Last_Name = d.Trainer.Last_Name; trainerModel.ID = d.Trainer.ID; trainerModel.Role_ID = d.Trainer.Role_ID; TotalModel.Student = db.Students.Where(i => i.Trainer_ID == d.Trainer.ID).Count(); TrainerTotalModel.Trainer = trainerModel; TrainerTotalModel.Total = TotalModel; TrainerTotalModelList.Add(TrainerTotalModel); } return(View(TrainerTotalModelList)); } catch (Exception ex) { return(RedirectToAction("Contact", "Home")); } }
public static void Total(this ScenarioContext context, TotalModel model) { context.Set(TotalKey, model); }
public ResultModel NewFirstAscendHillClimbingMethod(KnapsackModel model, double alpha, bool needObjectiveDetails = false) { //selec inital X at random BitArray X = XInit != null ? XInit : new RandomBitGeneration().GenerateBitArray(model.N); //initialize settings var neighborhood = new Neighborhood(); neighborhood.InitNFlip(1, model.N); var objectiveCalculation = new ObjectiveCalculation(); var xTotalModel = objectiveCalculation.CalculateNewObjective(X, model, alpha); new FileProcess().WriteFile(X, xTotalModel, "ResultFAHillClimbing"); //for objective Details var objectiveDetails = new List <double>(); if (needObjectiveDetails) { objectiveDetails.Add(xTotalModel.IsModelAppropriate ? xTotalModel.TotalCost : -1); } while (!neighborhood.stop) { BitArray Y = neighborhood.GetNextNeighborhood(X); var yTotalModel = objectiveCalculation.CalculateNewObjective(Y, model, alpha); if (xTotalModel.TotalCost < yTotalModel.TotalCost) { X = (BitArray)Y.Clone(); xTotalModel = new TotalModel { TotalCost = yTotalModel.TotalCost, TotalWeight = yTotalModel.TotalWeight, IsModelAppropriate = yTotalModel.IsModelAppropriate }; neighborhood.InitNFlip(1, model.N); new FileProcess().WriteFile(X, xTotalModel, "ResultFAHillClimbing"); if (needObjectiveDetails) { objectiveDetails.Add(xTotalModel.IsModelAppropriate ? xTotalModel.TotalCost : -1); } } else { neighborhood.MoveNext(); } } var resultModel = new ResultModel(); resultModel.ResultC = xTotalModel.TotalCost; resultModel.ResultW = xTotalModel.TotalWeight; resultModel.X = (BitArray)X.Clone(); if (needObjectiveDetails) { resultModel.ObjectiveDetails = objectiveDetails; } return(resultModel); }
// GET: ShoppingCart public ActionResult Index(Guid?id) { if (id == null) { ShoppingCartViewModel oModel = new ShoppingCartViewModel((List <ItemModel>)Session["itemList"], (TotalModel)Session["totModel"]); return(View(oModel)); } else { List <ItemModel> itemListModels = new List <ItemModel>(); List <ItemModel> existItemLists = new List <ItemModel>(); TotalModel existTotal = new TotalModel(); TotalModel oTotal = new TotalModel(); //Session["itemList"] = null; //Session["totModel"] = null; if (Session["itemList"] == null) { var oProduct = context.tblProducts.Where(x => x.ProductID == id).FirstOrDefault(); ItemModel oItem = new ItemModel(); oItem.ProductID = oProduct.ProductID; oItem.Name = oProduct.Name; oItem.Qty = 1; oItem.Rate = oProduct.Price.Value; oItem.ItemTotal = oProduct.Price.Value; itemListModels.Add(oItem); oTotal.Total = oItem.Rate * 1; Session["itemList"] = itemListModels; Session["totModel"] = oTotal; } else { existItemLists = (List <ItemModel>)Session["itemList"]; existTotal = (TotalModel)Session["totModel"]; var oProductExist = existItemLists.Where(x => x.ProductID == id).FirstOrDefault(); decimal totalVal = existTotal.Total; // bool isNewItem = false; if (oProductExist != null) { foreach (var item in existItemLists) { if (item.ProductID == oProductExist.ProductID) { item.Qty = item.Qty + 1; totalVal = totalVal + (1 * item.Rate); } } } else { var oProduct = context.tblProducts.Where(x => x.ProductID == id).FirstOrDefault(); ItemModel oItem = new ItemModel(); oItem.ProductID = oProduct.ProductID; oItem.Name = oProduct.Name; oItem.Qty = 1; oItem.Rate = oProduct.Price.Value; oItem.ItemTotal = oProduct.Price.Value; totalVal = totalVal + (oItem.Qty * oItem.Rate); existItemLists.Add(oItem); } //if (isNewItem) //{ //} oTotal.Total = totalVal; Session["itemList"] = existItemLists; Session["totModel"] = oTotal; } ShoppingCartViewModel oModel = new ShoppingCartViewModel((List <ItemModel>)Session["itemList"], (TotalModel)Session["totModel"]); return(View(oModel)); } }
public Output(TotalModel model) { }
public ActionResult Owner() { try { int GYM_ID = Convert.ToInt32(Session["GYM_ID"]); var Branche = db.Branches.Where(i => i.GYM_ID == GYM_ID && i.IS_Active == true).ToList(); List <BranchTotalModel> BranchTotalModelList = new List <BranchTotalModel>(); ViewBag.Total_Student = db.Students.Where(i => i.GYM_ID == GYM_ID).Count(); ViewBag.Total_Trainer = db.Trainers.Where(i => i.Role_ID == 3 && i.GYM_ID == GYM_ID).Count(); ViewBag.Total_Manager = db.Trainers.Where(i => i.Role_ID == 2 && i.GYM_ID == GYM_ID).Count(); ViewBag.Total_Branch = db.Branches.Where(i => i.GYM_ID == GYM_ID && i.IS_Active == true).Count(); ViewBag.Total_Offer = db.Offers.Where(i => i.GYM_ID == GYM_ID && i.Status == true).Count(); ViewBag.Total_Plane = db.Planes.Where(i => i.GYM_ID == GYM_ID && i.Is_Active == true).Count(); ViewBag.Visit = db.Demoes.Where(i => i.GYM_ID == GYM_ID && DbFunctions.TruncateTime(i.Date) == DbFunctions.TruncateTime(DateTime.Now)).Count(); ViewBag.Today_Joining = db.Demoes.Where(d => DbFunctions.TruncateTime(d.Date) == DbFunctions.TruncateTime(DateTime.Now) && d.GYM_ID == GYM_ID).Count(); ViewBag.New_Student = db.Students.Where(d => DbFunctions.TruncateTime(d.Start_Date) == DbFunctions.TruncateTime(DateTime.Now) && d.GYM_ID == GYM_ID).Count(); var Today_Earning = db.Fees.Where(i => i.GYM_ID == GYM_ID && DbFunctions.TruncateTime(i.Payment_Date) == DbFunctions.TruncateTime(DateTime.Now)).ToList(); var Earning = 0; foreach (var Earnings in Today_Earning) { Earning = Earning + Convert.ToInt32(Earnings.Payment_Amount); } ViewBag.Today_Earning = Earning; var Month_Earnings = db.Fees.Where(i => i.GYM_ID == GYM_ID && i.Payment_Date.Value.Month == DateTime.Now.Month).ToList(); var Earningss = 0; foreach (var Month_Earning in Month_Earnings) { Earningss = Earningss + Convert.ToInt32(Month_Earning.Payment_Amount); } ViewBag.Month_Earning = Earningss; foreach (var d in Branche) { BranchTotalModel BranchTotalModel = new BranchTotalModel(); BranchModel BranchModel = new BranchModel(); TotalModel TotalModel = new TotalModel(); BranchModel.ID = d.ID; BranchModel.Name = d.Name; TotalModel.Student = db.Students.Where(i => i.Branch_ID == d.ID).Count(); TotalModel.Trainer = db.Trainers.Where(i => i.Branvch_ID == d.ID && i.Role_ID == 3).Count(); TotalModel.Manager = db.Trainers.Where(i => i.Branvch_ID == d.ID && i.Role_ID == 2).Count(); TotalModel.Plane = db.Branch_Wise_Plane.Where(i => i.Branch_ID == d.ID && i.Status == true).Count(); TotalModel.Offer = db.Branch_Wise_Offer.Where(i => i.Branch_ID == d.ID && i.Status == true).Count(); TotalModel.Demo = db.Demoes.Where(i => i.Branch_ID == d.ID && DbFunctions.TruncateTime(i.Date) == DbFunctions.TruncateTime(DateTime.Now)).Count(); ViewBag.Today_Joining = db.Demoes.Where(i => DbFunctions.TruncateTime(i.Start_Date) == DbFunctions.TruncateTime(DateTime.Now) && i.Branch_ID == d.ID).Count(); ViewBag.New_Student = db.Students.Where(i => DbFunctions.TruncateTime(i.Start_Date) == DbFunctions.TruncateTime(DateTime.Now) && i.Branch_ID == d.ID).Count(); TotalModel.Today_Earning = Earning; TotalModel.Month_Earning = Earningss; BranchTotalModel.Total = TotalModel; BranchTotalModel.Branch = BranchModel; BranchTotalModelList.Add(BranchTotalModel); } return(View(BranchTotalModelList)); } catch (Exception ex) { return(RedirectToAction("Contact", "Home")); } }