Search Results

Search found 5 results on 1 pages for 'repopulation'.

Page 1/1 | 1 

  • ASP.NET MVC Form repopulation

    - by ListenToRick
    I have a controller with two actions: [AcceptVerbs("GET")] public ActionResult Add() { PrepareViewDataForAddAction(); return View(); } [AcceptVerbs("POST")] public ActionResult Add([GigBinderAttribute]Gig gig, FormCollection formCollection) { if (ViewData.ModelState.IsValid) { GigManager.Save(gig); return RedirectToAction("Index", gig.ID); } PrepareViewDataForAddAction(); return View(gig); } As you can see, when the form posts its data, the Add action uses a GigBinder (An implemenation of IModelBinder) In this binder I have: if (int.TryParse(bindingContext.HttpContext.Request.Form["StartDate.Hour"], out hour)) { gig.StartDate.Hour = hour; } else { bindingContext.ModelState.AddModelError("Doors", "You need to tell us when the doors open"); } The form contains a text box with id "StartDate.Hour". As you can see above, the GigBinder tests to see that the user has typed in an integer into the textbox with id "StartDate.Hour". If not, a model error is added to the modelstate using AddModelError. Since the gigs property gigs.StartDate.Hour is strongly typed, I cannot set its value to, for example, "TEST" if the user has typed this into the forms textbox. Hence, I cant set the value of gigs.StartDate.Hour since the user has entered a string rather than an integer. Since the Add Action returns the view and passes the model (return View(gig);) if the modelstate is invalid, when the form is re-displayed with validation mssages, the value "TEST" is not displayed in the textbox. Instead, it will be the default value of gig.StartDate.Hour. How do I get round this problem? I really stuck!

    Read the article

  • Evolutionary Algorithms: Optimal Repopulation Breakdowns

    - by Brian MacKay
    It's really all in the title, but here's a breakdown for anyone who is interested in Evolutionary Algorithms: In an EA, the basic premise is that you randomly generate a certain number of organisms (which are really just sets of parameters), run them against a problem, and then let the top performers survive. You then repopulate with a combination of crossbreeds of the survivors, mutations of the survivors, and also a certain number of new random organisms. Do that several thousand times, and efficient organisms arise. Some people also do things like introduce multiple "islands" of organisms, which are seperate populations that are allowed to crossbreed once in awhile. So, my question is: what are the optimal repopulation percentages? I have been keeping the top 10% performers, and repopulating with 30% crossbreeds and 30% mutations. The remaining 30% is for new organisms. I have also tried out the multiple island theory, and I'm interested in your results on that as well. It is not lost on me that this is exactly the type of problem an EA could solve. Are you aware of anyone trying that? Thanks in advance!

    Read the article

  • How do I make these fields autopopulate from the database?

    - by dmanexe
    I have an array, which holds values like this: $items_pool = Array ( [0] => Array ( [id] => 1 [quantity] => 1 ) [1] => Array ( [id] => 2 [quantity] => 1 ) [2] => Array ( [id] => 72 [quantity] => 6 ) [3] => Array ( [id] => 4 [quantity] => 1 ) [4] => Array ( [id] => 5 [quantity] => 1 ) [5] => Array ( [id] => 7 [quantity] => 1 ) [6] => Array ( [id] => 8 [quantity] => 1 ) [7] => Array ( [id] => 9 [quantity] => 1 ) [8] => Array ( [id] => 19 [quantity] => 1 ) [9] => Array ( [id] => 20 [quantity] => 1 ) [10] => Array ( [id] => 22 [quantity] => 1 ) [11] => Array ( [id] => 29 [quantity] => 0 ) ) Next, I have a form that I am trying to populate. It loops through the item database, prints out all the possible items, and checks the ones that are already present in $items_pool. <?php foreach ($items['items_poolpackage']->result() as $item): ?> <input type="checkbox" name="measure[<?=$item->id?>][checkmark]" value="<?=$item->id?>"> <?php endforeach; ?> I know what logically I'm trying to accomplish here, but I can't figure out the programming. What I'm looking for, written loosely is something like this (not real code): <input type="checkbox" name="measure[<?=$item->id?>][checkmark]" value="<?=$item->id?>" <?php if ($items_pool['$item->id']) { echo "SELECTED"; } else { }?>> Specifically this conditional loop through the array, through all the key values (the ID) and if there's a match, the checkbox is selected. <?php if ($items_pool['$item->id']) { echo "SELECTED"; } else { }?> I understand from a loop structured like this that it may mean a lot of 'extra' processing. TL;DR - I need to echo within a loop if the item going through the loop exists within another array.

    Read the article

  • How do I populate these fields from existing data?

    - by dmanexe
    I'm not sure how to make a few parts of my form to populate from data from an array I'm passing from the database. First is this <select> object. The key estimate_lead_id in the database holds the value, and I want the dropdown to auto-select based on the value from the database. <select name="estimate_lead_id"> <? foreach($leads->result() as $lead) { ?> <option value="<?=$lead->id?>"><?=$lead->lead_name?></option> <? } ?> </select> Second (this is a little more complex), I have created a script that loops through and gets all of the items from each respective category. What I can't get it to do though is loop through these items and only display the items in the estimate, and then fill the fields with the respective values from the database. <?php foreach ($items['items_poolconcretedecking']->result() as $item) { ?> <input type="checkbox" name="measure[<?=$item->id?>][checkmark]" value="<?=$item->id?>"> <input class="item_mult" value="" type="text" name="measure[<?=$item->id?>][quantity]" /> <?php } ?>

    Read the article

  • Flatten date range memberships retaining only the highest priority membership (TRANSACT-SQL)

    - by shadowranger
    Problem statement: A table contains an item_id, a category_id and a date range (begin_date and end_date). No item may be in more than one category on any given date (in general; during daily rebuilding it can be in an invalid state temporarily). By default, all items are added (and re-added if removed) to a category (derived from outside data) automatically on a daily basis, and their membership in that category matches the lifespan of the item (items have their own begin and end date, and usually spend their entire lives in the same category, which is why this matches). For items in category X, it is occasionally desirable to override the default category by adding them to category Y. Membership in category Y could entirely replace membership in category X (that is, the begin and end dates for membership in category Y would match the begin and end dates of the item itself), or it could override it for an arbitrary period of time (at the beginning, middle or end the item's lifespan, possibly overriding for short periods at multiple times). Membership in category Y is not renewed automatically and additions to that category is done by manual data entry. Every day, when category X is rebuilt, we get an overlap, where any item in category Y will now be in category X as well (which is forbidden, as noted previously). Goal: After each repopulation of category X (which is done in a rather complicated and fragile manner, and ideally would be left alone), I'm trying to find an efficient means of writing a stored procedure that: Identifies the overlaps Changes existing entries, adds new ones where necessary (such as in the case where an item starts in category X, switches to category Y, then eventually switches back to category X before ending), or removes entries (when an item is in category Y for its entire life) such that every item remains in category Y (and only Y) where specified, while category X membership is maintained when not overridden by category Y. Does not affect memberships of categories A, B, C, Z, etc., which do not have override categories and are built separately, by completely different rules. Note: It can be assumed that X membership covers the entire lifespan of the item before this procedure is called, so it is unnecessary to query any data outside this table. Bonus credit: If for some reason there are two adjacent or overlapping memberships in for the same item in category Y, stitching them together into a single entry is appreciated, but not necessary. Example: item_id category_id begin_date end_date 1 X 20080101 20090628 1 Y 20090101 20090131 1 Y 20090601 20090628 2 X 20080201 20080731 2 Y 20080201 20080731 Should become: item_id category_id begin_date end_date 1 X 20080101 20081231 1 Y 20090101 20090131 1 X 20090201 20090531 1 Y 20090601 20090628 2 Y 20080201 20080731 If it matters, this needs to work on SQL Server 2005 and SQL Server 2008

    Read the article

1