/// <summary> /// Runs a hybrid QAOA. /// </summary> public async Task <ExecutionResult> Run(string input, IChannel channel) { if (string.IsNullOrWhiteSpace(input)) { channel.Stderr("Please provide correct arguments"); return(ExecuteStatus.Error.ToExecutionResult()); } var args = JsonConvert.DeserializeObject <Arguments>(input); HybridQaoa hybridQaoa = new HybridQaoa(args.NumberOfIterations, args.p, args.ProblemInstance, args.NumberOfRandomStartingPoints, args.InitialBeta, args.InitialGamma); return(hybridQaoa.RunOptimization().ToExecutionResult()); }
public void RunHybridQaoaTest() { double[] dh = new Double[] { 0, 0 }; double[] dJ = new Double[] { 0, 1, 0, 0 }; int numberOfIterations = 50; int p = 2; int numberOfRandomStartingPoints = 2; ProblemInstance simpleMaxCut = new ProblemInstance(dh, dJ); HybridQaoa classicalOptimization = new HybridQaoa(numberOfIterations, p, simpleMaxCut, numberOfRandomStartingPoints); OptimalSolution optimalSolution = classicalOptimization.RunOptimization(); string optimizationResult1 = "01"; string optimizationResult2 = "10"; string result = optimalSolution.optimalVector; Console.WriteLine(result); Assert.IsTrue(result.Equals(optimizationResult1) || result.Equals(optimizationResult2), "Hybrid QAOA produced incorrect result."); }