Пример #1
0
	def test3(self):
		tlist = [1]
		case1 = solution()
		t1 = time.time()
		out = case1.compRange(tlist)
		t2 = time.time()
		print "Runtime for case2: " + str(t2 - t1) + " seconds"
		self.assertEqual( out,[] )
Пример #2
0
	def test1(self):
		tlist = [1,2,3,4,5,8,9,10]
		case1 = solution()
		t1 = time.time()
		out = case1.compRange(tlist)
		t2 = time.time()
		print "Runtime for case1: " + str(t2 - t1) + " seconds"
		self.assertEqual( out,["1->5", "8->10"] )
Пример #3
0
    def test_solution(self):
        numbers_to_sort = [
            1000, 100, 90, 80, 70, 60, 50, 40, 30, 30, 20, 10, 1
        ]
        expected = [1, 10, 20, 30, 30, 40, 50, 60, 70, 80, 90, 100, 1000]
        actual = solution(numbers_to_sort)

        self.assertEqual(actual, expected)
Пример #4
0
	def test3(self):
		test = list()
		for i in range(1,10001):
			if i%8 == 0:
				continue
			else:
				test.append(i)
		case1 = solution()
		t1 = time.time()
		out = case1.compRange(test)
		t2 = time.time()
		print "Runtime for case2: " + str(t2 - t1) + " seconds"
		self.assertEqual( out, ['1->7', '9->15', '17->23', '25->31', '33->39', '41->47', '49->55', '57->63', '65->71', '73->79', '81->87', '89->95', '97->103', '105->111', '113->119', '121->127', '129->135', '137->143', '145->151', '153->159', '161->167', '169->175', '177->183', '185->191', '193->199', '201->207', '209->215', '217->223', '225->231', '233->239', '241->247', '249->255', '257->263', '265->271', '273->279', '281->287', '289->295', '297->303', '305->311', '313->319', '321->327', '329->335', '337->343', '345->351', '353->359', '361->367', '369->375', '377->383', '385->391', '393->399', '401->407', '409->415', '417->423', '425->431', '433->439', '441->447', '449->455', '457->463', '465->471', '473->479', '481->487', '489->495', '497->503', '505->511', '513->519', '521->527', '529->535', '537->543', '545->551', '553->559', '561->567', '569->575', '577->583', '585->591', '593->599', '601->607', '609->615', '617->623', '625->631', '633->639', '641->647', '649->655', '657->663', '665->671', '673->679', '681->687', '689->695', '697->703', '705->711', '713->719', '721->727', '729->735', '737->743', '745->751', '753->759', '761->767', '769->775', '777->783', '785->791', '793->799', '801->807', '809->815', '817->823', '825->831', '833->839', '841->847', '849->855', '857->863', '865->871', '873->879', '881->887', '889->895', '897->903', '905->911', '913->919', '921->927', '929->935', '937->943', '945->951', '953->959', '961->967', '969->975', '977->983', '985->991', '993->999', '1001->1007', '1009->1015', '1017->1023', '1025->1031', '1033->1039', '1041->1047', '1049->1055', '1057->1063', '1065->1071', '1073->1079', '1081->1087', '1089->1095', '1097->1103', '1105->1111', '1113->1119', '1121->1127', '1129->1135', '1137->1143', '1145->1151', '1153->1159', '1161->1167', '1169->1175', '1177->1183', '1185->1191', '1193->1199', '1201->1207', '1209->1215', '1217->1223', '1225->1231', '1233->1239', '1241->1247', '1249->1255', '1257->1263', '1265->1271', '1273->1279', '1281->1287', '1289->1295', '1297->1303', '1305->1311', '1313->1319', '1321->1327', '1329->1335', '1337->1343', '1345->1351', '1353->1359', '1361->1367', '1369->1375', '1377->1383', '1385->1391', '1393->1399', '1401->1407', '1409->1415', '1417->1423', '1425->1431', '1433->1439', '1441->1447', '1449->1455', '1457->1463', '1465->1471', '1473->1479', '1481->1487', '1489->1495', '1497->1503', '1505->1511', '1513->1519', '1521->1527', '1529->1535', '1537->1543', '1545->1551', '1553->1559', '1561->1567', '1569->1575', '1577->1583', '1585->1591', '1593->1599', '1601->1607', '1609->1615', '1617->1623', '1625->1631', '1633->1639', '1641->1647', '1649->1655', '1657->1663', '1665->1671', '1673->1679', '1681->1687', '1689->1695', '1697->1703', '1705->1711', '1713->1719', '1721->1727', '1729->1735', '1737->1743', '1745->1751', '1753->1759', '1761->1767', '1769->1775', '1777->1783', '1785->1791', '1793->1799', '1801->1807', '1809->1815', '1817->1823', '1825->1831', '1833->1839', '1841->1847', '1849->1855', '1857->1863', '1865->1871', '1873->1879', '1881->1887', '1889->1895', '1897->1903', '1905->1911', '1913->1919', '1921->1927', '1929->1935', '1937->1943', '1945->1951', '1953->1959', '1961->1967', '1969->1975', '1977->1983', '1985->1991', '1993->1999', '2001->2007', '2009->2015', '2017->2023', '2025->2031', '2033->2039', '2041->2047', '2049->2055', '2057->2063', '2065->2071', '2073->2079', '2081->2087', '2089->2095', '2097->2103', '2105->2111', '2113->2119', '2121->2127', '2129->2135', '2137->2143', '2145->2151', '2153->2159', '2161->2167', '2169->2175', '2177->2183', '2185->2191', '2193->2199', '2201->2207', '2209->2215', '2217->2223', '2225->2231', '2233->2239', '2241->2247', '2249->2255', '2257->2263', '2265->2271', '2273->2279', '2281->2287', '2289->2295', '2297->2303', '2305->2311', '2313->2319', '2321->2327', '2329->2335', '2337->2343', '2345->2351', '2353->2359', '2361->2367', '2369->2375', '2377->2383', '2385->2391', '2393->2399', '2401->2407', '2409->2415', '2417->2423', '2425->2431', '2433->2439', '2441->2447', '2449->2455', '2457->2463', '2465->2471', '2473->2479', '2481->2487', '2489->2495', '2497->2503', '2505->2511', '2513->2519', '2521->2527', '2529->2535', '2537->2543', '2545->2551', '2553->2559', '2561->2567', '2569->2575', '2577->2583', '2585->2591', '2593->2599', '2601->2607', '2609->2615', '2617->2623', '2625->2631', '2633->2639', '2641->2647', '2649->2655', '2657->2663', '2665->2671', '2673->2679', '2681->2687', '2689->2695', '2697->2703', '2705->2711', '2713->2719', '2721->2727', '2729->2735', '2737->2743', '2745->2751', '2753->2759', '2761->2767', '2769->2775', '2777->2783', '2785->2791', '2793->2799', '2801->2807', '2809->2815', '2817->2823', '2825->2831', '2833->2839', '2841->2847', '2849->2855', '2857->2863', '2865->2871', '2873->2879', '2881->2887', '2889->2895', '2897->2903', '2905->2911', '2913->2919', '2921->2927', '2929->2935', '2937->2943', '2945->2951', '2953->2959', '2961->2967', '2969->2975', '2977->2983', '2985->2991', '2993->2999', '3001->3007', '3009->3015', '3017->3023', '3025->3031', '3033->3039', '3041->3047', '3049->3055', '3057->3063', '3065->3071', '3073->3079', '3081->3087', '3089->3095', '3097->3103', '3105->3111', '3113->3119', '3121->3127', '3129->3135', '3137->3143', '3145->3151', '3153->3159', '3161->3167', '3169->3175', '3177->3183', '3185->3191', '3193->3199', '3201->3207', '3209->3215', '3217->3223', '3225->3231', '3233->3239', '3241->3247', '3249->3255', '3257->3263', '3265->3271', '3273->3279', '3281->3287', '3289->3295', '3297->3303', '3305->3311', '3313->3319', '3321->3327', '3329->3335', '3337->3343', '3345->3351', '3353->3359', '3361->3367', '3369->3375', '3377->3383', '3385->3391', '3393->3399', '3401->3407', '3409->3415', '3417->3423', '3425->3431', '3433->3439', '3441->3447', '3449->3455', '3457->3463', '3465->3471', '3473->3479', '3481->3487', '3489->3495', '3497->3503', '3505->3511', '3513->3519', '3521->3527', '3529->3535', '3537->3543', '3545->3551', '3553->3559', '3561->3567', '3569->3575', '3577->3583', '3585->3591', '3593->3599', '3601->3607', '3609->3615', '3617->3623', '3625->3631', '3633->3639', '3641->3647', '3649->3655', '3657->3663', '3665->3671', '3673->3679', '3681->3687', '3689->3695', '3697->3703', '3705->3711', '3713->3719', '3721->3727', '3729->3735', '3737->3743', '3745->3751', '3753->3759', '3761->3767', '3769->3775', '3777->3783', '3785->3791', '3793->3799', '3801->3807', '3809->3815', '3817->3823', '3825->3831', '3833->3839', '3841->3847', '3849->3855', '3857->3863', '3865->3871', '3873->3879', '3881->3887', '3889->3895', '3897->3903', '3905->3911', '3913->3919', '3921->3927', '3929->3935', '3937->3943', '3945->3951', '3953->3959', '3961->3967', '3969->3975', '3977->3983', '3985->3991', '3993->3999', '4001->4007', '4009->4015', '4017->4023', '4025->4031', '4033->4039', '4041->4047', '4049->4055', '4057->4063', '4065->4071', '4073->4079', '4081->4087', '4089->4095', '4097->4103', '4105->4111', '4113->4119', '4121->4127', '4129->4135', '4137->4143', '4145->4151', '4153->4159', '4161->4167', '4169->4175', '4177->4183', '4185->4191', '4193->4199', '4201->4207', '4209->4215', '4217->4223', '4225->4231', '4233->4239', '4241->4247', '4249->4255', '4257->4263', '4265->4271', '4273->4279', '4281->4287', '4289->4295', '4297->4303', '4305->4311', '4313->4319', '4321->4327', '4329->4335', '4337->4343', '4345->4351', '4353->4359', '4361->4367', '4369->4375', '4377->4383', '4385->4391', '4393->4399', '4401->4407', '4409->4415', '4417->4423', '4425->4431', '4433->4439', '4441->4447', '4449->4455', '4457->4463', '4465->4471', '4473->4479', '4481->4487', '4489->4495', '4497->4503', '4505->4511', '4513->4519', '4521->4527', '4529->4535', '4537->4543', '4545->4551', '4553->4559', '4561->4567', '4569->4575', '4577->4583', '4585->4591', '4593->4599', '4601->4607', '4609->4615', '4617->4623', '4625->4631', '4633->4639', '4641->4647', '4649->4655', '4657->4663', '4665->4671', '4673->4679', '4681->4687', '4689->4695', '4697->4703', '4705->4711', '4713->4719', '4721->4727', '4729->4735', '4737->4743', '4745->4751', '4753->4759', '4761->4767', '4769->4775', '4777->4783', '4785->4791', '4793->4799', '4801->4807', '4809->4815', '4817->4823', '4825->4831', '4833->4839', '4841->4847', '4849->4855', '4857->4863', '4865->4871', '4873->4879', '4881->4887', '4889->4895', '4897->4903', '4905->4911', '4913->4919', '4921->4927', '4929->4935', '4937->4943', '4945->4951', '4953->4959', '4961->4967', '4969->4975', '4977->4983', '4985->4991', '4993->4999', '5001->5007', '5009->5015', '5017->5023', '5025->5031', '5033->5039', '5041->5047', '5049->5055', '5057->5063', '5065->5071', '5073->5079', '5081->5087', '5089->5095', '5097->5103', '5105->5111', '5113->5119', '5121->5127', '5129->5135', '5137->5143', '5145->5151', '5153->5159', '5161->5167', '5169->5175', '5177->5183', '5185->5191', '5193->5199', '5201->5207', '5209->5215', '5217->5223', '5225->5231', '5233->5239', '5241->5247', '5249->5255', '5257->5263', '5265->5271', '5273->5279', '5281->5287', '5289->5295', '5297->5303', '5305->5311', '5313->5319', '5321->5327', '5329->5335', '5337->5343', '5345->5351', '5353->5359', '5361->5367', '5369->5375', '5377->5383', '5385->5391', '5393->5399', '5401->5407', '5409->5415', '5417->5423', '5425->5431', '5433->5439', '5441->5447', '5449->5455', '5457->5463', '5465->5471', '5473->5479', '5481->5487', '5489->5495', '5497->5503', '5505->5511', '5513->5519', '5521->5527', '5529->5535', '5537->5543', '5545->5551', '5553->5559', '5561->5567', '5569->5575', '5577->5583', '5585->5591', '5593->5599', '5601->5607', '5609->5615', '5617->5623', '5625->5631', '5633->5639', '5641->5647', '5649->5655', '5657->5663', '5665->5671', '5673->5679', '5681->5687', '5689->5695', '5697->5703', '5705->5711', '5713->5719', '5721->5727', '5729->5735', '5737->5743', '5745->5751', '5753->5759', '5761->5767', '5769->5775', '5777->5783', '5785->5791', '5793->5799', '5801->5807', '5809->5815', '5817->5823', '5825->5831', '5833->5839', '5841->5847', '5849->5855', '5857->5863', '5865->5871', '5873->5879', '5881->5887', '5889->5895', '5897->5903', '5905->5911', '5913->5919', '5921->5927', '5929->5935', '5937->5943', '5945->5951', '5953->5959', '5961->5967', '5969->5975', '5977->5983', '5985->5991', '5993->5999', '6001->6007', '6009->6015', '6017->6023', '6025->6031', '6033->6039', '6041->6047', '6049->6055', '6057->6063', '6065->6071', '6073->6079', '6081->6087', '6089->6095', '6097->6103', '6105->6111', '6113->6119', '6121->6127', '6129->6135', '6137->6143', '6145->6151', '6153->6159', '6161->6167', '6169->6175', '6177->6183', '6185->6191', '6193->6199', '6201->6207', '6209->6215', '6217->6223', '6225->6231', '6233->6239', '6241->6247', '6249->6255', '6257->6263', '6265->6271', '6273->6279', '6281->6287', '6289->6295', '6297->6303', '6305->6311', '6313->6319', '6321->6327', '6329->6335', '6337->6343', '6345->6351', '6353->6359', '6361->6367', '6369->6375', '6377->6383', '6385->6391', '6393->6399', '6401->6407', '6409->6415', '6417->6423', '6425->6431', '6433->6439', '6441->6447', '6449->6455', '6457->6463', '6465->6471', '6473->6479', '6481->6487', '6489->6495', '6497->6503', '6505->6511', '6513->6519', '6521->6527', '6529->6535', '6537->6543', '6545->6551', '6553->6559', '6561->6567', '6569->6575', '6577->6583', '6585->6591', '6593->6599', '6601->6607', '6609->6615', '6617->6623', '6625->6631', '6633->6639', '6641->6647', '6649->6655', '6657->6663', '6665->6671', '6673->6679', '6681->6687', '6689->6695', '6697->6703', '6705->6711', '6713->6719', '6721->6727', '6729->6735', '6737->6743', '6745->6751', '6753->6759', '6761->6767', '6769->6775', '6777->6783', '6785->6791', '6793->6799', '6801->6807', '6809->6815', '6817->6823', '6825->6831', '6833->6839', '6841->6847', '6849->6855', '6857->6863', '6865->6871', '6873->6879', '6881->6887', '6889->6895', '6897->6903', '6905->6911', '6913->6919', '6921->6927', '6929->6935', '6937->6943', '6945->6951', '6953->6959', '6961->6967', '6969->6975', '6977->6983', '6985->6991', '6993->6999', '7001->7007', '7009->7015', '7017->7023', '7025->7031', '7033->7039', '7041->7047', '7049->7055', '7057->7063', '7065->7071', '7073->7079', '7081->7087', '7089->7095', '7097->7103', '7105->7111', '7113->7119', '7121->7127', '7129->7135', '7137->7143', '7145->7151', '7153->7159', '7161->7167', '7169->7175', '7177->7183', '7185->7191', '7193->7199', '7201->7207', '7209->7215', '7217->7223', '7225->7231', '7233->7239', '7241->7247', '7249->7255', '7257->7263', '7265->7271', '7273->7279', '7281->7287', '7289->7295', '7297->7303', '7305->7311', '7313->7319', '7321->7327', '7329->7335', '7337->7343', '7345->7351', '7353->7359', '7361->7367', '7369->7375', '7377->7383', '7385->7391', '7393->7399', '7401->7407', '7409->7415', '7417->7423', '7425->7431', '7433->7439', '7441->7447', '7449->7455', '7457->7463', '7465->7471', '7473->7479', '7481->7487', '7489->7495', '7497->7503', '7505->7511', '7513->7519', '7521->7527', '7529->7535', '7537->7543', '7545->7551', '7553->7559', '7561->7567', '7569->7575', '7577->7583', '7585->7591', '7593->7599', '7601->7607', '7609->7615', '7617->7623', '7625->7631', '7633->7639', '7641->7647', '7649->7655', '7657->7663', '7665->7671', '7673->7679', '7681->7687', '7689->7695', '7697->7703', '7705->7711', '7713->7719', '7721->7727', '7729->7735', '7737->7743', '7745->7751', '7753->7759', '7761->7767', '7769->7775', '7777->7783', '7785->7791', '7793->7799', '7801->7807', '7809->7815', '7817->7823', '7825->7831', '7833->7839', '7841->7847', '7849->7855', '7857->7863', '7865->7871', '7873->7879', '7881->7887', '7889->7895', '7897->7903', '7905->7911', '7913->7919', '7921->7927', '7929->7935', '7937->7943', '7945->7951', '7953->7959', '7961->7967', '7969->7975', '7977->7983', '7985->7991', '7993->7999', '8001->8007', '8009->8015', '8017->8023', '8025->8031', '8033->8039', '8041->8047', '8049->8055', '8057->8063', '8065->8071', '8073->8079', '8081->8087', '8089->8095', '8097->8103', '8105->8111', '8113->8119', '8121->8127', '8129->8135', '8137->8143', '8145->8151', '8153->8159', '8161->8167', '8169->8175', '8177->8183', '8185->8191', '8193->8199', '8201->8207', '8209->8215', '8217->8223', '8225->8231', '8233->8239', '8241->8247', '8249->8255', '8257->8263', '8265->8271', '8273->8279', '8281->8287', '8289->8295', '8297->8303', '8305->8311', '8313->8319', '8321->8327', '8329->8335', '8337->8343', '8345->8351', '8353->8359', '8361->8367', '8369->8375', '8377->8383', '8385->8391', '8393->8399', '8401->8407', '8409->8415', '8417->8423', '8425->8431', '8433->8439', '8441->8447', '8449->8455', '8457->8463', '8465->8471', '8473->8479', '8481->8487', '8489->8495', '8497->8503', '8505->8511', '8513->8519', '8521->8527', '8529->8535', '8537->8543', '8545->8551', '8553->8559', '8561->8567', '8569->8575', '8577->8583', '8585->8591', '8593->8599', '8601->8607', '8609->8615', '8617->8623', '8625->8631', '8633->8639', '8641->8647', '8649->8655', '8657->8663', '8665->8671', '8673->8679', '8681->8687', '8689->8695', '8697->8703', '8705->8711', '8713->8719', '8721->8727', '8729->8735', '8737->8743', '8745->8751', '8753->8759', '8761->8767', '8769->8775', '8777->8783', '8785->8791', '8793->8799', '8801->8807', '8809->8815', '8817->8823', '8825->8831', '8833->8839', '8841->8847', '8849->8855', '8857->8863', '8865->8871', '8873->8879', '8881->8887', '8889->8895', '8897->8903', '8905->8911', '8913->8919', '8921->8927', '8929->8935', '8937->8943', '8945->8951', '8953->8959', '8961->8967', '8969->8975', '8977->8983', '8985->8991', '8993->8999', '9001->9007', '9009->9015', '9017->9023', '9025->9031', '9033->9039', '9041->9047', '9049->9055', '9057->9063', '9065->9071', '9073->9079', '9081->9087', '9089->9095', '9097->9103', '9105->9111', '9113->9119', '9121->9127', '9129->9135', '9137->9143', '9145->9151', '9153->9159', '9161->9167', '9169->9175', '9177->9183', '9185->9191', '9193->9199', '9201->9207', '9209->9215', '9217->9223', '9225->9231', '9233->9239', '9241->9247', '9249->9255', '9257->9263', '9265->9271', '9273->9279', '9281->9287', '9289->9295', '9297->9303', '9305->9311', '9313->9319', '9321->9327', '9329->9335', '9337->9343', '9345->9351', '9353->9359', '9361->9367', '9369->9375', '9377->9383', '9385->9391', '9393->9399', '9401->9407', '9409->9415', '9417->9423', '9425->9431', '9433->9439', '9441->9447', '9449->9455', '9457->9463', '9465->9471', '9473->9479', '9481->9487', '9489->9495', '9497->9503', '9505->9511', '9513->9519', '9521->9527', '9529->9535', '9537->9543', '9545->9551', '9553->9559', '9561->9567', '9569->9575', '9577->9583', '9585->9591', '9593->9599', '9601->9607', '9609->9615', '9617->9623', '9625->9631', '9633->9639', '9641->9647', '9649->9655', '9657->9663', '9665->9671', '9673->9679', '9681->9687', '9689->9695', '9697->9703', '9705->9711', '9713->9719', '9721->9727', '9729->9735', '9737->9743', '9745->9751', '9753->9759', '9761->9767', '9769->9775', '9777->9783', '9785->9791', '9793->9799', '9801->9807', '9809->9815', '9817->9823', '9825->9831', '9833->9839', '9841->9847', '9849->9855', '9857->9863', '9865->9871', '9873->9879', '9881->9887', '9889->9895', '9897->9903', '9905->9911', '9913->9919', '9921->9927', '9929->9935', '9937->9943', '9945->9951', '9953->9959', '9961->9967', '9969->9975', '9977->9983', '9985->9991', '9993->9999'])
Пример #5
0
def RIDFS(limit):
    if frontier.empty():
        return "failure"
    # get next un-visited node in stack
    u_node = frontier.get()[1]
    while visited_hashes.has_key(u_node.state.hash):
        u_node = frontier.get()[1]
    # u_node.state.toPrint()
    visited_hashes[u_node.state.hash] = True

    if u_node.state.goal_test():
        return solution(u_node)

    if limit == 0:
        cutoff_occurred = True
        return "cutoff"

    # else look athe chilren
    cutoff_occurred = False

    # gather up the children and push them onto the stack
    # gather up the children
    child_nodes = [Node(p, u_node) for p in u_node.state.children()]
    for c in child_nodes:
        frontier.put((c.metric, c))
        #print "child" + str(c.state.puzzle)

    result = RIDFS(limit - 1)
    if result == "cutoff":
        cutoff_occurred = True
    else:
        if not result == "failure":
            return result
    if cutoff_occurred:
        return "cutoff"
    else:
        return "failure"
Пример #6
0
    def test_solution(self):
        numbers_to_sort = [10, 9, 8, 7, 6, 5, 4, 3, 3, 2, 1, 1]
        expected = [1, 1, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10]
        actual = solution(numbers_to_sort)

        self.assertEqual(actual, expected)
Пример #7
0
 def execute(self, s, k, expectedResult):
     actualResult = solution(s, k)
     self.assertEqual(expectedResult, actualResult)
Пример #8
0
from Solution import solution

A=[3,1,2,4,3]
result = solution(A)
print result
Пример #9
0
from Solution import solution


result = solution(10,85,30)
print result
Пример #10
0
def woa(maxiteration, population, dimension, objf, lb, ub):
    # initialize position vector and score for the leader
    Leader_pos=numpy.zeros(dimension)
    Leader_score=float("inf")  #change this to -inf for maximization problems
    
    
    #Initialize the positions of search agents
    Positions= numpy.random.uniform(0, 1, (population, dimension)) * (ub - lb) + lb
    
    #Initialize convergence
    convergence_curve=numpy.zeros(maxiteration)
    
    
    ############################
    s=solution()

    print("MFO is optimizing  \""+objf.__name__+"\"")    

    timerStart=time.time() 
    s.startTime=time.strftime("%Y-%m-%d-%H-%M-%S")
    ############################
    
    t=0  # Loop counter
    
    # Main loop
    while t<maxiteration:
        for i in range(0, population):
            
            # Return back the search agents that go beyond the boundaries of the search space
            
            #Positions[i,:]=checkBounds(Positions[i,:],lb,ub)          
            Positions[i,:]=numpy.clip(Positions[i,:], lb, ub)
            
            # Calculate objective function for each search agent
            fitness=objf(Positions[i,:])
            
            # Update the leader
            if fitness<Leader_score: # Change this to > for maximization problem
                Leader_score=fitness # Update alpha
                Leader_pos=Positions[i,:]
            
            
        
        
        a=2-t*((2) / maxiteration) # a decreases linearly fron 2 to 0 in Eq. (2.3)
        
        # a2 linearly dicreases from -1 to -2 to calculate t in Eq. (3.12)
        a2=-1+t*((-1) / maxiteration)
        
        # Update the Position of search agents 
        for i in range(0, population):
            r1=random.random() # r1 is a random number in [0,1]
            r2=random.random() # r2 is a random number in [0,1]
            
            A=2*a*r1-a  # Eq. (2.3) in the paper
            C=2*r2      # Eq. (2.4) in the paper
            
            
            b=1               #  parameters in Eq. (2.5)
            l=(a2-1)*random.random()+1   #  parameters in Eq. (2.5)
            
            p = random.random()        # p in Eq. (2.6)
            
            for j in range(0, dimension):
                
                if p<0.5:
                    if abs(A)>=1:
                        rand_leader_index = math.floor(population * random.random())
                        X_rand = Positions[rand_leader_index, :]
                        D_X_rand=abs(C*X_rand[j]-Positions[i,j]) 
                        Positions[i,j]=X_rand[j]-A*D_X_rand      
                        
                    elif abs(A)<1:
                        D_Leader=abs(C*Leader_pos[j]-Positions[i,j]) 
                        Positions[i,j]=Leader_pos[j]-A*D_Leader      
                    
                    
                elif p>=0.5:
                  
                    distance2Leader=abs(Leader_pos[j]-Positions[i,j])
                    # Eq. (2.5)
                    Positions[i,j]=distance2Leader*math.exp(b*l)*math.cos(l*2*math.pi)+Leader_pos[j]
                    
      
        
        convergence_curve[t]=Leader_score
        if (t%1==0):
               print(['At iteration '+ str(t)+ ' the best fitness is '+ str(Leader_score)])
        t=t+1
    
    timerEnd=time.time()  
    s.endTime=time.strftime("%Y-%m-%d-%H-%M-%S")
    s.executionTime=timerEnd-timerStart
    s.convergence=convergence_curve
    s.optimizer="WOA"   
    s.objfname=objf.__name__
    
    
    
    return s