public void testGreedyBestFirstSearch() { try { // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[] // {2,0,5,6,4,8,3,7,1}); // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[] // {0,8,7,6,5,4,3,2,1}); EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 7, 1, 8, 0, 4, 6, 2, 3, 5 }); Problem problem = new Problem(board, EightPuzzleFunctionFactory .getActionsFunction(), EightPuzzleFunctionFactory .getResultFunction(), new EightPuzzleGoalTest()); Search search = new GreedyBestFirstSearch(new GraphSearch(), new ManhattanHeuristicFunction()); SearchAgent agent = new SearchAgent(problem, search); Assert.assertEquals(49, agent.getActions().size()); Assert.assertEquals("197", agent.getInstrumentation().getProperty( "nodesExpanded")); Assert.assertEquals("140", agent.getInstrumentation().getProperty( "queueSize")); Assert.assertEquals("141", agent.getInstrumentation().getProperty( "maxQueueSize")); } catch (Exception e) { e.printStackTrace(); Assert.fail("Exception thrown."); } }
public override ProblemCollection Check(TypeNode type) { Type runtimeType = type.GetRuntimeType(); if ( IsTestFixture( runtimeType ) ) { string ignoreReason = Reflect.GetIgnoreReason( runtimeType ); if ( ignoreReason.Trim().Length == 0 ) { Resolution resolution = GetNamedResolution( "TestFixture", type.Name.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } System.Reflection.MethodInfo[] methods = runtimeType.GetMethods( BindingFlags.Instance | BindingFlags.Public ); foreach( MethodInfo method in methods ) { string methodIgnoreReason = Reflect.GetIgnoreReason( method ); if ( methodIgnoreReason.Trim().Length == 0 ) { string[] parameters = new string[] { type.Name.Name, method.Name }; Resolution resolution = GetNamedResolution( "TestCase", parameters ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } } if ( base.Problems.Count > 0 ) return base.Problems; } return base.Check (type); }
public override IEnumerable<Problem> Validate(Dictionary<Guid, SitecoreDeployInfo> projectItems, XDocument scprojDocument) { //loop through each item in the TDS project foreach (var item in projectItems) { //check that the item path starts with a value specified in the Additional Properties list //otherwise we just ignore the item if (Settings.Properties.Any( x => item.Value.Item.SitecoreItemPath.StartsWith(x, StringComparison.InvariantCultureIgnoreCase))) { var fld = item.Value.ParsedItem.Fields["Initial State"]; if (fld != null && fld == String.Empty) { //when a problem is found get the position of it in the TDS project file ProblemLocation position = GetItemPosition(scprojDocument, item.Value.Item); //create a report which will be displayed in the Visual Studio Error List Problem report = new Problem(this, position) { Message = string.Format("This workflow is missing an intial state: {0}", item.Value.ParsedItem.Path) }; yield return report; } } } }
public override Solution Solve(Problem problem) { var specimens = GenerateRandomPopulation(problem); var bestSpecimen = FindBestSpecimen(specimens).Clone(); for (var i = 0; i < config.numberOfIterations; i++) { specimens = specimens.OrderBy(o => o.Value).ToList(); var nextPopulation = specimens.Take(config.specimenPoolSize / 4).ToList(); for (var j = 0; j < config.specimenPoolSize / 4; j++) { nextPopulation.Add(new Specimen(problem, random)); } nextPopulation.AddRange( specimens.Shuffle(random) .Take(specimens.Count / 2) .AsQueryable() .Zip(specimens, (a, b) => mutation.Execute(crossover.Execute(a, b)))); // nextPopulation.Add(Mutation.Execute(Crossover.Execute(_specimens[j], _specimens[j + 1]))); // } specimens = nextPopulation; bestSpecimen = FindBestSpecimen(specimens).Clone(); //Console.Error.WriteLine(string.Format(" {0}", bestSpecimen.Value)); } return bestSpecimen; }
/// <summary> /// Visits the call. /// </summary> /// <param name="destination">The destination.</param> /// <param name="receiver">The receiver.</param> /// <param name="callee">The callee.</param> /// <param name="arguments">The arguments.</param> /// <param name="isVirtualCall">if set to <c>true</c> [is virtual call].</param> /// <param name="programContext">The program context.</param> /// <param name="stateBeforeInstruction">The state before instruction.</param> /// <param name="stateAfterInstruction">The state after instruction.</param> public override void VisitCall( Variable destination, Variable receiver, Method callee, ExpressionList arguments, bool isVirtualCall, Microsoft.Fugue.IProgramContext programContext, Microsoft.Fugue.IExecutionState stateBeforeInstruction, Microsoft.Fugue.IExecutionState stateAfterInstruction) { if ((callee.DeclaringType.GetRuntimeType() == typeof(X509ServiceCertificateAuthentication) || callee.DeclaringType.GetRuntimeType() == typeof(X509ClientCertificateAuthentication)) && (callee.Name.Name.Equals("set_CertificateValidationMode", StringComparison.InvariantCultureIgnoreCase))) { IAbstractValue value = stateBeforeInstruction.Lookup((Variable)arguments[0]); IIntValue intValue = value.IntValue(stateBeforeInstruction); if (intValue != null) { X509CertificateValidationMode mode = (X509CertificateValidationMode)intValue.Value; if (mode != X509CertificateValidationMode.ChainTrust) { Resolution resolution = base.GetResolution(mode.ToString(), X509CertificateValidationMode.ChainTrust.ToString()); Problem problem = new Problem(resolution, programContext); base.Problems.Add(problem); } } } base.VisitCall(destination, receiver, callee, arguments, isVirtualCall, programContext, stateBeforeInstruction, stateAfterInstruction); }
public override ProblemCollection Check(TypeNode type) { Type runtimeType = type.GetRuntimeType(); if ( IsTestFixture( runtimeType ) ) { System.Reflection.MethodInfo[] methods = runtimeType.GetMethods( BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly ); // Note that if an method with an invalid signature is marked as a setup method, then // it will be considered as not marked and hence setupMethod will be null. // Same applies for tearDownMethod. System.Reflection.MethodInfo setupMethod = Reflect.GetSetUpMethod( runtimeType ); System.Reflection.MethodInfo tearDownMethod = Reflect.GetTearDownMethod( runtimeType ); System.Reflection.MethodInfo fixtureSetupMethod = Reflect.GetFixtureSetUpMethod( runtimeType ); System.Reflection.MethodInfo fixtureTearDownMethod = Reflect.GetFixtureTearDownMethod( runtimeType ); foreach( System.Reflection.MethodInfo methodInfo in methods ) { if ( !IsTestCaseMethod( methodInfo ) && ( methodInfo != setupMethod ) && ( methodInfo != tearDownMethod ) && ( methodInfo != fixtureSetupMethod ) && ( methodInfo != fixtureTearDownMethod ) ) { Resolution resolution = GetResolution( methodInfo.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } } if ( base.Problems.Count > 0 ) return base.Problems; } return base.Check (type); }
public override ProblemCollection Check(TypeNode type) { Type runtimeType = type.GetRuntimeType(); if ( IsTestFixture( runtimeType ) ) { System.Reflection.MethodInfo[] methods = runtimeType.GetMethods(); foreach( System.Reflection.MethodInfo methodInfo in methods ) { // if method starts with "test" and is not marked as [Test], // then an explicit [Test] should be added since NUnit will // treat it as a test case. if ( IsTestCaseMethod( methodInfo ) && !Reflect.HasTestAttribute( methodInfo ) ) { Resolution resolution = GetResolution( methodInfo.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } } if ( base.Problems.Count > 0 ) return base.Problems; } return base.Check (type); }
public override ProblemCollection Check(TypeNode type) { Type runtimeType = type.GetRuntimeType(); if ( IsTestFixture( runtimeType ) && !runtimeType.IsAbstract && type.IsVisibleOutsideAssembly ) { MemberList constructors = type.GetConstructors(); for ( int i = 0; i < constructors.Length; ++i ) { Member constructor = constructors[i]; // only examine non-static constructors Microsoft.Cci.InstanceInitializer instanceConstructor = constructor as Microsoft.Cci.InstanceInitializer; if ( instanceConstructor == null ) continue; // trigger errors for non-default constructors. if ( ( instanceConstructor.Parameters.Length != 0 ) && ( !instanceConstructor.IsPrivate ) ) { Resolution resolution = GetResolution( runtimeType.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } } if ( base.Problems.Count > 0 ) return base.Problems; } return base.Check (type); }
protected void btnSubmit_Click(object sender, EventArgs e) { Problem pro = new Problem(); pro.Description = txtProblemDesc.Text; pro.Date = DateTime.Now; pro.Location = txtLocation.Text; //string filePath = fileUploadImage.PostedFile.FileName; //string filename = Path.GetFileName(filePath); //string ext = Path.GetExtension(filename); //string contenttype = String.Empty; //if (contenttype != String.Empty) //{ string fileName = Path.GetFileName(fileUploadImage.PostedFile.FileName); Stream fs = fileUploadImage.PostedFile.InputStream; BinaryReader br = new BinaryReader(fs); Byte[] bytes = br.ReadBytes((Int32)fs.Length); pro.Photo = bytes; //} if(p.InsertProblem(pro) == true) { Response.Write("Added"); txtProblemDesc.Text = ""; txtLocation.Text = ""; } }
/// <summary> /// Construct the object. /// </summary> /// <param name="mask">Fix certain parameters or leave null.</param> /// <param name="problem">Problem to optimize.</param> public MESH(double?[] mask, Problem problem) : base(problem) { Debug.Assert(mask == null || mask.Length == problem.Dimensionality); Mask = mask; }
public void testAStarSearch() { // added to narrow down bug report filed by L.N.Sudarshan of // Thoughtworks and Xin Lu of UCI try { // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[] // {2,0,5,6,4,8,3,7,1}); // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[] // {0,8,7,6,5,4,3,2,1}); EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 7, 1, 8, 0, 4, 6, 2, 3, 5 }); Problem problem = new Problem(board, EightPuzzleFunctionFactory .getActionsFunction(), EightPuzzleFunctionFactory .getResultFunction(), new EightPuzzleGoalTest()); Search search = new AStarSearch(new GraphSearch(), new ManhattanHeuristicFunction()); SearchAgent agent = new SearchAgent(problem, search); Assert.assertEquals(23, agent.getActions().size()); Assert.assertEquals("926", agent.getInstrumentation().getProperty( "nodesExpanded")); Assert.assertEquals("534", agent.getInstrumentation().getProperty( "queueSize")); Assert.assertEquals("535", agent.getInstrumentation().getProperty( "maxQueueSize")); } catch (Exception e) { e.printStackTrace(); Assert.fail("Exception thrown"); } }
public override IEnumerable<Problem> Validate(Dictionary<Guid, SitecoreDeployInfo> projectItems, XDocument scprojDocument) { //loop through each item in the TDS project foreach (var item in projectItems) { //check that the item path starts with a value specified in the Additional Properties list //otherwise we just ignore the item if (Settings.Properties.Any( x => item.Value.Item.SitecoreItemPath.StartsWith(x, StringComparison.InvariantCultureIgnoreCase))) { var editable = item.Value.ParsedItem.Fields["Editable"]; var datasourcelocation = item.Value.ParsedItem.Fields["Datasource Location"]; if (!string.IsNullOrEmpty(datasourcelocation) && editable != null && editable == String.Empty) { //when a problem is found get the position of it in the TDS project file ProblemLocation position = GetItemPosition(scprojDocument, item.Value.Item); //create a report which will be displayed in the Visual Studio Error List Problem report = new Problem(this, position) { Message = string.Format("A datasource driven sublayout must have it's 'Editable' setting checked: {0}", item.Value.ParsedItem.Path) }; yield return report; } } } }
//problem - we have to be over restrictive: //(xor a b c) + know(a) + know(b) = know(c) private void AddReasoningActions(Problem p) { foreach (CompoundFormula cf in p.Hidden) { Actions.AddRange(CreateReasoningActions(cf)); } }
public void SolveReturnsAllSolutions() { var problem = new Problem(); var algorithm = new DepthFirstSearchAlgorithm(); var solutions = algorithm.Solve(problem); }
void CollectEntityByID(MooDB db, int id) { problem = (from p in db.Problems where p.ID == id select p).SingleOrDefault<Problem>(); revision = problem == null ? null : problem.LatestSolution; }
/// <summary> /// Creates Solution instance. /// </summary> /// <param name="problem">Corresponding problem instance.</param> /// <param name="data">Final solution data.</param> /// <param name="computationsTime">Total computations time.</param> /// <param name="timeoutOccured">True if the computations were stopped due to timeout.</param> public Solution(Problem problem, byte[] data, ulong computationsTime, bool timeoutOccured) { Problem = problem; Data = data; ComputationsTime = computationsTime; TimeoutOccured = timeoutOccured; }
void CollectEntityByRevision(MooDB db, int id) { revision = (from r in db.SolutionRevisions where r.ID == id select r).SingleOrDefault<SolutionRevision>(); problem = revision == null ? null : revision.Problem; }
public static EditProblemViewModel GetEditProblemViewModel(Problem problem) { var epvm = new EditProblemViewModel(); epvm.Author = problem.Author.UserName; epvm.Name = problem.Name; epvm.Text = problem.Text; epvm.SelectedCategoryId = problem.CategoryId; epvm.IsBlocked = problem.IsBlocked; var sb = new StringBuilder(); foreach (var tag in problem.Tags) { sb.Append(tag.Name); sb.Append(','); } epvm.TagsString = sb.ToString(); sb.Clear(); foreach (var ans in problem.CorrectAnswers) { sb.Append(ans.Text); sb.Append(';'); } sb.Remove(sb.Length - 1, 1); epvm.Answers = sb.ToString(); return epvm; }
/// <summary> /// Checks the specified type. /// </summary> /// <param name="type">The type.</param> /// <returns></returns> public override ProblemCollection Check(TypeNode type) { AttributeNode attribute = SemanticRulesUtilities.GetAttribute(type, ServiceContractAttribute); if (SemanticRulesUtilities.HasAttribute<ServiceContractAttribute>(attribute)) { List<string> duplicated = new List<string>(); foreach (Member member in type.Members) { if (SemanticRulesUtilities.GetAttribute(member, OperationContractAttribute) != null) { if (duplicated.Contains(member.Name.Name)) { Resolution resolution = base.GetResolution(member.FullName); Problem problem = new Problem(resolution, type.SourceContext); base.Problems.Add(problem); } else { duplicated.Add(member.Name.Name); } } } } return base.Problems; }
public override void Handle(Problem context,StateChangeInfo stateChangeInfo) { var newState = new ProblemAcceptedState(); newState.IsCurrent = true; context.CurrentState.IsCurrent = false; context.States.Add(newState); }
public static Problem createRandomProblem(int numClasses) { Problem prob = new Problem(); prob.bias = -1; prob.l = random.Next(100) + 1; prob.n = random.Next(100) + 1; prob.x = new Feature[prob.l][]; prob.y = new double[prob.l]; for (int i = 0; i < prob.l; i++) { prob.y[i] = random.Next(numClasses); ISet<int> randomNumbers = new HashSet<int>(); int num = random.Next(prob.n) + 1; for (int j = 0; j < num; j++) { randomNumbers.Add(random.Next(prob.n) + 1); } List<int> randomIndices = new List<int>(randomNumbers); randomIndices.Sort(); prob.x[i] = new Feature[randomIndices.Count]; for (int j = 0; j < randomIndices.Count; j++) { prob.x[i][j] = new Feature(randomIndices[j], random.NextDouble()); } } return prob; }
public override ProblemCollection Check(TypeNode type) { Type runtimeType = type.GetRuntimeType(); if ( IsTestFixture( runtimeType ) ) { // if more than one setup, trigger error. if ( GetTestSetupMethodsCount( runtimeType ) > 1 ) { Resolution resolution = GetNamedResolution( "SetUp", type.Name.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); return base.Problems; } // if more than one setup, trigger error. if ( GetFixtureSetupMethodsCount( runtimeType ) > 1 ) { Resolution resolution = GetNamedResolution( "TestFixtureSetUp", type.Name.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); return base.Problems; } } return base.Check (type); }
public Specimen(Problem problem, Random random) { Problem = problem; Random = random; SetRandomDistribution(); CalculateSpecimentValue(); }
public override ProblemCollection Check(TypeNode type) { Type runtimeType = type.GetRuntimeType(); if ( IsTestFixture( runtimeType ) ) { PropertyInfo[] properties; // check for instance public properties properties = runtimeType.GetProperties( BindingFlags.Instance | BindingFlags.Public ); foreach( PropertyInfo instanceProperty in properties ) { Resolution resolution = GetResolution( instanceProperty.DeclaringType.Name, instanceProperty.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } // check for static public properties, whether declared in the class // or one of its base classes. properties = runtimeType.GetProperties( BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy ); foreach( PropertyInfo staticProperty in properties ) { Resolution resolution = GetResolution( staticProperty.DeclaringType.Name, staticProperty.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } } if ( base.Problems.Count > 0 ) return base.Problems; return base.Check (type); }
public override ProblemCollection Check(TypeNode type) { Type runtimeType = type.GetRuntimeType(); if ( IsTestFixture( runtimeType ) ) { System.Reflection.MethodInfo[] methods = runtimeType.GetMethods( BindingFlags.Instance | BindingFlags.Public ); foreach( MethodInfo method in methods ) { if ( !Reflect.HasTestAttribute( method ) && ( Reflect.HasExpectedExceptionAttribute( method ) || Reflect.HasIgnoreAttribute( method ) || Reflect.HasCategoryAttribute( method ) || Reflect.HasExplicitAttribute( method ) ) ) { Resolution resolution = GetResolution( method.Name ); Problem problem = new Problem( resolution ); base.Problems.Add( problem ); } } if ( base.Problems.Count > 0 ) return base.Problems; } return base.Check (type); }
public GUI(SortAlgorithm s) { theProblem = ProblemFactory.createActualProblem(); theAlgorithm = s; InitializeComponent(); initializeGUI(); }
public void AddProblem(ProblemMetadata problemMetadata) { ArgumentUtility.CheckNotNull ("problemMetadata", problemMetadata); var resolution = GetResolution (problemMetadata.ExpectedFragment, problemMetadata.GivenFragment); var problem = new Problem (resolution, problemMetadata.SourceContext, CheckId); Problems.Add (problem); }
public string[] Normalize(Problem problem) { var tags = problem.RawTags.Where(x => rawTagsMapping.ContainsKey(x)).Select(x => rawTagsMapping[x]).ToArray(); var corrections = correctionsByProblemUrl.ContainsKey(problem.Url) ? correctionsByProblemUrl[problem.Url] : new Correction[0]; return Apply(tags, corrections); }
protected void AddItemToSet(HashSet<Problem> set, Problem item) { if (Accept(item)) { set.Add(item); } }
public BeliefState(Problem p) { Problem = p; m_sPredecessor = null; m_lObserved = new HashSet<Predicate>(); Unknown = new HashSet<Predicate>(); m_lHiddenFormulas = new List<CompoundFormula>(); m_lOriginalHiddenFormulas = new List<CompoundFormula>(); m_dMapPredicatesToFormulas = new Dictionary<GroundedPredicate, List<int>>(); m_lEfficientHidden = new List<EfficientFormula>(); m_dMapPredicatesToIndexes = new Dictionary<GroundedPredicate, int>(); m_dMapIndexToPredicate = new List<GroundedPredicate>(); m_dMapPredicateToEfficientFormula = new List<List<int>>(); AvailableActions = new List<Action>(); UnderlyingEnvironmentState = null; m_cfCNFHiddenState = new CompoundFormula("and"); FunctionValues = new Dictionary<string, double>(); foreach (string sFunction in Problem.Domain.Functions) { FunctionValues[sFunction] = 0.0; } bsCOUNT++; ID = bsCOUNT; }