Abstract LDTA’04 Preliminary Version Parameterized LR Parsing

合集下载

C#中abstract的用法详解

C#中abstract的用法详解

C#中abstract的⽤法详解abstract可以⽤来修饰类,⽅法,属性,索引器和时间,这⾥不包括字段. 使⽤abstrac修饰的类,该类只能作为其他类的基类,不能实例化,⽽且abstract修饰的成员在派⽣类中必须全部实现,不允许部分实现,否则编译异常. 如:using System;namespace ConsoleApplication8{class Program{static void Main(string[] args){BClass b = new BClass();b.m1();}}abstract class AClass{public abstract void m1();public abstract void m2();}class BClass : AClass{public override void m1(){throw new NotImplementedException();}//public override void m2()//{// throw new NotImplementedException();//}}}Abstract classes have the following features:抽象类拥有如下特征:1,抽象类不能被实例化, 但可以有实例构造函数, 类是否可以实例化取决于是否拥有实例化的权限 (对于抽象类的权限是abstract, 禁⽌实例化),即使不提供构造函数, 编译器也会提供默认构造函数;2,抽象类可以包含抽象⽅法和访问器;3,抽象类不能使⽤sealed修饰, sealed意为不能被继承;4,所有继承⾃抽象类的⾮抽象类必须实现所有的抽象成员,包括⽅法,属性,索引器,事件;abstract修饰的⽅法有如下特征:1,抽象⽅法即是虚拟⽅法(隐含);2,抽象⽅法只能在抽象类中声明;3,因为抽象⽅法只是声明, 不提供实现, 所以⽅法只以分号结束,没有⽅法体,即没有花括号部分;如public abstract void MyMethod();4,override修饰的覆盖⽅法提供实现,且只能作为⾮抽象类的成员;5,在抽象⽅法的声明上不能使⽤virtual或者是static修饰.即不能是静态的,⼜因为abstract已经是虚拟的,⽆需再⽤virtual强调.抽象属性尽管在⾏为上与抽象⽅法相似,但仍有有如下不同:1,不能在静态属性上应⽤abstract修饰符;2,抽象属性在⾮抽象的派⽣类中覆盖重写,使⽤override修饰符;抽象类与接⼝:1,抽象类必须提供所有接⼝成员的实现;2,继承接⼝的抽象类可以将接⼝的成员映射位抽象⽅法.如:interface I{void M();}abstract class C: I{public abstract void M();}抽象类实例:// abstract_keyword.cs// 抽象类using System;abstract class BaseClass // 抽象类{protected int _x = 100; //抽象类可以定义字段,但不可以是抽象字段,也没有这⼀说法.protected int _y = 150;public BaseClass(int i) //可以定义实例构造函数,仅供派⽣的⾮抽象类调⽤; 这⾥显式提供构造函数,编译器将不再提供默认构造函数. {fielda = i;}public BaseClass(){}private int fielda;public static int fieldsa = 0;public abstract void AbstractMethod(); // 抽象⽅法public abstract int X { get; } //抽象属性public abstract int Y { get; }public abstract string IdxString { get; set; } //抽象属性public abstract char this[int i] { get; } //抽象索引器}class DerivedClass : BaseClass{private string idxstring;private int fieldb;//如果基类中没有定义⽆参构造函数,但存在有参数的构造函数,//那么这⾥派⽣类得构造函数必须调⽤基类的有参数构造函数,否则编译出错public DerivedClass(int p): base(p) //这⾥的:base(p)可省略,因为基类定义了默认的⽆参构造函数{fieldb = p;}public override string IdxString //覆盖重新属性{get{return idxstring;}set{idxstring = value;}}public override char this[int i] //覆盖重写索引器{get { return IdxString[i]; }}public override void AbstractMethod(){_x++;_y++;}public override int X // 覆盖重写属性{get{return _x + 10;}}public override int Y // 覆盖重写属性{get{return _y + 10;}}static void Main(){DerivedClass o = new DerivedClass(1);o.AbstractMethod();Console.WriteLine("x = {0}, y = {1}", o.X, o.Y);}}以上所述是⼩编给⼤家介绍的C#中abstract的⽤法详解,希望对⼤家有所帮助,如果⼤家有任何疑问请给我留⾔,⼩编会及时回复⼤家的。

Preparation and examination of the properties of complex scandium fluorides

Preparation and examination of the properties of complex scandium fluorides

1319Preparation and Examination of the Propertiesof Complex Scandium FluoridesYu. V. Sokolova and R. N. CherepaninMoscow Institute of Steel and Alloys, National Research Technological University, Moscow, RussiaReceived December 6, 2010Abstract —Precipitation of scandium with sodium fluoride from an ammonium hydrogen difluoride solution was examined at the molar ratios of Na to Sc within 1–14 and different initial concentrations of scandium in solution. The composition of the resulting precipitate was determined by X-ray phase analysis method. Thesolubility of the scandium compounds synthesized was examined. ISSN 1070-4272, Russian Journal of Applied Chemistry, 2011, Vol. 84, No. 8, pp. 1319–1323. © Pleiades Publishing, Ltd., 2011.Original Russian Text © Yu.V. Sokolova, R.N. Cherepanin, 2011, published in Zhurnal Prikladnoi Khimii, 2011, Vol. 84, No. 8, pp. 1254–1258.The available published data on the properties of complex scandium fluorides are mostly concerned with the solid state. The phase diagrams of the MF–ScF 3 (M = Li, Na, K, Rb, Cs, NH 4, Ag, Tl) and other systems are presented in [1].Data concerning the occurrence and properties of complex scandium fluorides in solution are scarce. In the early twentieth century Meyer [2] discovered solubility of scandium(III) fluoride in solutions of alkali-metal and ammonium fluorides. Sterba–Bohm [3] described the synthesis of (NH 4)3ScF 6 and its decomposition into a number of compounds when dissolved in water. A more recent study of the solubility isotherm of (NH 4)3ScF 6 in an ammonium fluoride solution at 25°C showed that incongruent dissolution of the complex salt at the fluoride ion concentrations under 1.8 M leads to formation of congruently soluble ammonium tetrafluoroscandate NH 4ScF 4 (solubility in water at 25°C 1.29 g l –1, or 9.28 × 10–3 mol l –1). At the fluoride ion concentrations above 1.8 M scandium occurs in solution as hexa-fluoroscandate ion [4, 5].Tananaev and Golubev [6, 7] examined the ScCl 3–KF–H 2O system [6, 7] and, based on the optical density and molar electrical conductivity data for the solutions characterized by molar ratio of F to Sc n ranging from 1 to 10, presumed that ScF 3 (n = 3) andK 3ScF 6 (n = 6) are formed, and at higher n values, KScF 4·0.1H 2O and K 2.5ScF 5.66·H 2O (in the presence of 0.2 M KF in solution). The X-ray diffraction data reportedin those studies do not correspond to the currently known parameters for KScF 4, KSc 2F 7, K 5Sc 3F 14, and K 3ScF 6 (prepared by solid-phase syn-thesis procedure) [1, 8], i.e., most likely refer to solid solutions. We studied the interaction of a scandium(III) chloride solu-tion with crystalline KHF 2 and revealed formation of scan-dium(III) fluoride at n = 2–3, of a mixture of ScF 3 with KSc 2F 7 at n = 4, of KSc 2F 7 at n = 5–7, and of K 5Sc 3F 14 at n = 10–12 [9]. A relatively low degree of precipita-tion of scandium (80%) in preparation of scandium(III) fluoride, as well as the formation of a KSc 2F 7 gel, prevent the use of the above-mentioned system for quantitative recovery of scandium from solution.Complex scandium fluorides were prepared by the reaction between scandium(III) chloride and sodium fluoride solutions [10]. The conditions for preparation of scandium fluoride were determined (solid phase had the composition ScF 3·0.16 Н2О), as well as those for the synthesis of sodium tetrafluoroscandate in the form of NaScF 4·H 2O. As to the occurrence of Na 3ScF 6, whose preparation was reported in that study, this fact should not be taken as proved. The maximal F/Sc ratio obtained for the precipitate was 5.76, and the X-ray phase analysis data reported in that study are inconsistent with the currently known characteristics ofNa 3ScF 6. Consequently, those findings need clarification. Here, we explored the conditions for the synthesis of complex scandium fluorides from scandium solution in ammonium hydrogen difluoride with the use of sodium fluoride.DOI: 10.1134/S1070427211080040SOKOLOVA, CHEREPANIN 1320Fig. 1. Degree of precipitation S of Sc(III) from 10% NH4HF2 solution vs. Sc(III) concentration in the initial solution. m: (1) 3, (2) 1.5, (3) 1, and (4) 0.5. Fig. 2. Degree of precipitation S, %, of Sc(III) from 10% NH4HF2 solution vs. molar ratio of Na to Sc m. сSc, g l–1: (1) 1.8, (2) 1.5, and (3) 0.67.S, % S, %c Sc, g l–1mEXPERIMENTALThe initial solutions of scandium in ammonium hydrogen difluoride were obtained by the reaction of0.1–0.2 g of scandium oxide (OS-99.0 grade) with 100 ml of 10% NH4HF2 at 80–90°C. The insoluble residue was separated from the solution by filtration. The precipitation of scandium from NH4HF2 solution was examined with solutions containing 0.6–2 g l–1 scandium as an example.The Sc(III) and Na(I) concentrations in the solu-tions were determined by the inductively coupled plasma emission spectrometry on a Labtam V-310 Plasma Spectrometer and a Perkin-Elmer AAnalyst 300 atomic absorption spectrometer. The lower determination limit of the elements was 10–6 %, andthe determination error did not exceed 20%. The F–and NH4+ concentrations in the solutions were deter-mined with an ANION-410 pH-meter/ion meter and ELIS-131 F and ELIS-121 NH4 ion-selective electrodes. The X-ray phase analysis was carried outon a DRON-3 automated X-ray diffractometer with monochromatized Cu Kαradiation. The resulting spectra were processed using a software package for X-ray analysis of polycrystalline solids [11]. We determinedthe phase composition of the samples, as well as the lattice constants (the latter, with the accuracy Δa/a =0.0015).Ivanov–Emin et al. [5] reported that, in NH4F solution, Sc(III) occurs in the form of hexafluoro-scandate ion, which is apparently true for NH4HF2 solution as well. Introduction of sodium fluoride, either solid or in the form of solution, into an ammo-nium hydrogen difluoride solution containing the hexafluoroscandate ion causes formation of a scandium-containing precipitate. We examined the degree of precipitation of scan-dium with crystalline sodium fluoride in relation to theinitial concentration of Sc(III) in solution and to themolar ratio of Na to Sc m. Figures 1 and 2 showrespectively how the degree of precipitation ofscandium from 10% NH4HF2 solution with sodiumfluoride varies with the Sc(III) concentration in theinitial solution at different molar ratios m and with themolar ratio m at different Sc(III) concentration in theinitial solution.It is seen that, at Sc(III) concentrations under 0.5 g l–1, scandium precipitation is incomplete; in the concentra-tion range 0.5–1.5 g l–1 precipitation requires aconsiderable amount of the precipitation agent; and atthe Sc(III) concentration of 1.5 g l–1 and above thedegree of precipitation from the NH4HF2 solutionreaches 96% even at m = 1.5.The precipitates resulted from introduction into solution of Sc(III) in 10% NH4HF2 of solid NaF understirring and of a NaF solution have differentcompositions, specifically, within the m = 1–14 rangethey are represented by a mixture of ScF3, Na3ScF6, andNa(NH4)2ScF6 (Table 1). Figure 3 shows the linediagram of the powder patterns for the components ofthe mixture obtained in experiment no. 4.These results suggest proceeding of the following reactions upon introduction of sodium fluoride into anNH4HF2 solution:(NH4)3ScF6 + NaF = Na(NH4)2ScF6 + NH4F, (1)(NH4)3ScF6 + 3NaF = Na3ScF6 + 3NH4F. (2)A variable number of phases obtained under closeprecipitation conditions is evidently associated withhigh local supersaturations occurring both duringintroduction of solid sodium fluoride and in solution.RUSSIAN JOURNAL OF APPLIED CHEMISTRY Vol. 84 No. 8 2011RUSSIAN JOURNAL OF APPLIED CHEMISTRY Vol. 84 No. 8 2011PREPARATION AND EXAMINATION OF THE PROPERTIES 1321Initialconcentration ofSc, g l –1 m Precipitate composition,a %Precipitated Sc, % ScF 3 Na 3ScF 6 Na(NH 4)2ScF 6NaF 1 0.67 1 ~20 ~25 ~55 – Not determined2 1.0 1.3 11.9 20.3 67.8 – '' 3 0.67 1.5a ~45~45 ~10 – 82.1 4 1.0 1.5 7.2 6.2 86.6 – Not determined5 1.5 1.5 100 – – – 95.76 1.8 1.5 5 8 87 – Not determined7 0.67 3 ~20 ~22 ~58 – 91.0 8 1.5 3 30.4 46.0 23.6 – 99.4 9 1.5 4.5 3.9 10.1 84.2 1.9 95.1 10b 1.5 9 24.5 28.8 10.8 28.4 96.9 11b1.5146.224.47.359.699.4Exp. no. l/s , ml g –1 Degree of salt decomposition, %Na/Sc molar ratio in the precipitate 150 24.0 2.7 (mixture of NaScF 4 with Na 3ScF 6)a 250 68.7 1.1 (mixture of NaScF 4 with Na 3ScF 6) 300 73.51.0 (NaScF 4) 400 75.2 0.9 (mixture of NaScF 4 with ScF 3) 50089.50.4 (mixture of NaScF 4 with ScF 3)Table 1. Precipitation of Sc(III) from 10% NH 4HF 2 solution with sodium fluoride at 20°C. The precipitate composition was determined by X-ray phase analysis accurately to within 0.1%, except for experiment nos. 1, 3, and 7 aPrecipitated with 4% solution of sodium fluoride. b The rest is sodium fluorosilicate from ammonium hydrogen difluoride and sodium fluoride.Table 2. Degree of decomposition of complex scandium fluoride with water at different liquid to solid ratios (T = 20°C)aGiven in parentheses is the composition of the compounds, determined by X-ray phase analysis.At m ≥ 4.5 the precipitate contains sodium fluoride, which is due to the achievement of the salt solubility limit.The presence of scandium(III) fluoride in the mixture may be associated with involvement of the most stable ScF 2+ ion (stability constant 107 [12]) into interaction by the following scheme:ScF 2+ + HF 2–→ ScF 3 + H + (3) or with incongruent dissolution of the resulting complex salts.To determine the conditions conducive to decom-position of complex fluoride Na 3ScF 6 we examined the interaction of a mixture of Na 3ScF 6 and NaF (it wasobtained by the reaction of a scandium(III) chloride solution with an overstoichiometric amount of sodiumfluoride, the total composition being 3.2 NaF·ScF 3) with water at different liquid to solid ratios. The time of establishment of equilibrium was identified from aconstant concentration of the F – ion in solution. The degree of decomposition of the salt was determinedfrom the loss in the precipitate weight during theexperiment. Our results (Table 2) suggest incongruent dissolu-tion of Na 3ScF 6 in water with formation of sodiumRUSSIAN JOURNAL OF APPLIED CHEMISTRY Vol. 84 No. 8 2011SOKOLOVA, CHEREPANIN1322 Fig. 3. Line diagrams of the X-ray powder diffraction patterns of (a) Na(NH 4)2ScF 6 (structural type сF72/5), (b) Na 3ScF 6 (structural type mP20/13), and (c) ScF 3 (structural type hR4/10). (2θ) Bragg’s angle.(a)(b)(c)2θ, degPREPARATION AND EXAMINATION OF THE PROPERTIES 1323tetrafluoroscandate, as well as its decomposition by the following schemes:(3) Incongruent solubility in water and dilute solu-tions of mineral acids with formation of scandium(III) fluoride was revealed for NaScF4 and (NH4)2NaScF6.ACKNOWLEDGMENTSThe authors are grateful to V.G. Miskar’yants from GIREDMET Federal State Unitary Enterprise and T.A. Sviridova from the Center for Composite Materials, Moscow Institute of Steel and Alloys, National Research Technological University, for assistance in conducting the studies.REFERENCES1. Sobolev, B.P., The Rare Earth Trifluorides: Part 1: TheHigh Temperature Chemistry of the Rare EarthTrifluorides: Institute of Crystallography, Moscow,Russia; Institut d’Estudis Catalans, Barcelona, Spain,2000.2. Meyer, R., Z. Anorg. Chem., 1914, vol. 86, p. 257.3. Sterba-Bohm, J., Bull. Soc. Chim. France, 1920, vol. 4,p.27.4. Ivanov-Emin, B.N., Susanina, T.N., and Ogorodniko-va, L.A., Zh. Neorg. Khim., 1966, vol. 11, no. 3, pp.504–509.5. Ivanov-Emin, B.N., Susanina, T.N., and Ezhov, A.I.,Zh. Neorg. Khim., 1967, vol. 12, no. 1, pp. 23–28.6. Tananaev, I.V. and Golubev, O.F., Neorg. Mater., 1966,vol. 2, no. 8, pp. 1403–1409.7. Golubev, O.F., Study of the Formation, Composition,and Some Properties of Complex Scandium Fluorides,Cand. Sci. Dissertation, Moscow: 1967.8. Champarnaud-Mesjard, J.C. and Frit, B., J. Less-Comm.Met., 1991, vol. 167, no. 2, pp. 319–327.9. Sokolova, Yu.V., Cherepanin, R.N., and Sagalova, T.B.,Izv. Vyssh. Uchebn. Zaved., Tsvet. Met., 2006, no. 2, pp.35–40.10. Tananaev, I.V. and Golubev, O.F., Neorg. Mater., 1966,vol. 2, no. 6, pp. 1097–1104.11. Shelekhov, E.V. and Sviridova, T.A., Metalloved.Termich. Obrab. Metal., 2000, no. 8, pp. 16–19.12. Komissarova, L.N., Neorganicheskaya i analiticheskayakhimiyaskandiya (Inorganic and Analytical Chemistry of Scandium), Moscow: URSS, 2001.Na3ScF6 NaScF4 + 2NaF, (4)NaScF4 ScF3 + 2NaF. (5) However, even at large liquid to solid ratios weobtained a mixture of NaScF4 with ScF3.Treatment of the initial mixture of scandiumfluorides with 1% HCl solution at 70°C at the liquid tosolid ratio of ca. 50 (w/w) for 30 min led to a two-stepformation of scandium(III) fluoride. A similar result(under identical conditions) was obtained upon treatment of the salt mixture with 1% nitric acid solution. Treatment of the precipitates obtained in experiment nos. 7–9 (Table 1) with dilute solutions ofthe same mineral acids also resulted in formation of scandium(III) fluoride. These findings suggest thatNa3ScF6, NaScF4, and Na(NH4)2ScF6 show incon-gruent dissolution in an acid medium by schemes (4)–(6):Na(NH4)2ScF6 ScF3 + 2NH4F + NaF. (6) Apparently, the equilibrium of reactions (4)–(6) inan acid medium shifts to the right because of a decrease in the concentration of the free fluoride iondue to formation of hydrogen difluoride ion HF2–.Our results allow interpreting the data reported in[10] as due to partial decomposition of the resultingsodium hexafluoroscandate because of incongruent dissolution of this compound with formation of amixture of sodium hexafluoroscandate, sodium tetra-fluoroscandate, and possibly scandium(III) fluoride.CONCLUSIONS(1) It was found that introduction of sodiumfluoride into a solution of ammonium hexafluoro-scandate in NH4НF2 at molar ratios of F to Sc within1–14 leads to formation of the precipitate consisting ofa mixture of ScF3, Na3ScF6, and Na(NH4)2ScF6 indifferent ratios.(2) It was shown that Na3ScF6 undergoes incongruent dissolution in water with formation ofsodium tetrafluoroscandate.RUSSIAN JOURNAL OF APPLIED CHEMISTRY Vol. 84 No. 8 2011。

ABSTRACT

ABSTRACT

Semantic Web Services: description requirements and current technologiesRubén Lara Holger Lausen Sinuhé Arroyora@uibk.ac.at usen@uibk.ac.at sinuhe.arroyo@uibk.ac.atJos de Bruijn Dieter Fenseljos.de-bruijn@uibk.ac.at dieter.fensel@uibk.ac.atUniversität Innsbruck/Technikerstrasse, 136020, Innsbruck, AustriaABSTRACTSemantic Web Services aim at providing a new level of functionality on top of the current Web and current services, by enabling automatic discovery, composition, invocation and interoperation of Web Services. Different efforts are addressing some of the requirements to enable such next generation services, with different degree of success. Nevertheless, to achieve the main goals addressed by Semantic Web Services, an appropriate semantic description, supporting automation of discovery, composition, invocation and interoperation, must be defined. In this paper, a set of requirements on the information a Semantic Web Service must expose in order to fulfill these major objectives is presented. These requirements are related to the different initiatives in the area, and proposals for useful extensions and combinations of these efforts are discussed.Categories and Subject DescriptorsH.3.5 [Information Storage and Retrieval]: Online Information Services – web-based services, commercial services.General TermsStandardization, Languages.KeywordsWeb services, semantics, semantic web, semantic web services, semantic web services description, service ontology, WSMF, DAML-S, BPEL4WS, BPML, WSCI. 1.INTRODUCTIONWeb services extend the Web from a distributed source of information to a distributed source of service. Semantic Web has added machine-interpretable information to Web content in order to provide intelligent access to heterogeneous and distributed information. In a similar way, Semantic Web concepts are used to define intelligent web services, i.e., services supporting automatic discovery, composition, invocation and interoperation. This joint application of Semantic Web concepts and web services in order to realize intelligent web services is usually referred as Semantic Web Services.Due to the huge potential impact of semantic web services (SWSs for short) in areas like enterprise application integration and electronic commerce, several efforts, both academic and industrial, have jumped into the arena with the purpose of bringing semantic web services to its full potential. These initiatives are addressing different aspects of the requirements needed to realize semantic web services. They are sometimes complementary, but conflicts between the different approaches also appear. These efforts try to improve current web service technology around SOAP, WSDL and UDDI, which provides very limited support for real automation of services.One of these initiatives is the Web Services Modeling Framework (WSMF), which aims at providing an appropriate conceptual model for developing and describing services and their composition, based on the principles of maximal decoupling and scalable mediation [8].Another running project is DAML-S, a DARPA effort to describe an ontology of web services with the objective of making web services computer-interpretable and hence enabling discovery, invocation, interoperation, composition, verification and execution monitoring of services [5].BPEL4WS [1] and BPML [4]/WSCI [20] have similar functionalities, both aiming at defining a language to describe process models, as well as public process interfaces and servicechoreography support, to provide conversational and interoperation means for web services.Regarding W3C activities in the area, its initiative to define a setof requirements on service description pays little or no attentionto semantic support, hence offering a weak basis to make automation of functionality possible [21].Among the presented approaches, WSMF is the one with the widest scope, as it describes a full-fledged framework with the purpose of making the use of semantic web services a reality. Nevertheless, a concrete realization of the conceptual requirements it presents is still under development in the contextof the EU-funded project SWWS1. DAML-S focuses on providing semantics to web services descriptions, although some caveats, limitations and lacks have been identified within the proposed ontology. The initiatives focusing on the modeling of business processes, BPEL4WS and BPML/WSCI, do not incorporate any semantics to their modeling primitives, neither for private nor for public processes, thus providing limited support for dynamic discovery, composition and invocation [18].Whatever the approach and intended purpose, every initiative relies on a specific way to describe web services. Discovery, composition, invocation and interoperation strongly depend on how services are described and exposed for subsequent use. The way a service is described determines to what extent other constructs can provide automation support.WSMF proposes a service description framework which fulfillsthe requirements for semantic web services. Nevertheless, it needs some refinements and a specific grounding of the proposed description concepts. Therefore, the approach presented in this paper takes this framework as a starting point to determine the requirements for a meaningful service description.In this paper, and taking WSMF as a basis, we present a set of requirements for web services description and present grounding guidelines considering the features provided by current efforts. The paper is structured as follows. In section 2, capabilities are presented as the central description support for discovery and composition. Section 3 presents description needs for interoperation of services. Section 4 addresses the concrete grounding of services for invocation. In Section 5, other issues such as service compensation are discussed. Finally, section 6 presents conclusions and future work.2.Capabilities and description requirementsfor discovery and compositionAutomatic discovery and composition of services are probably the biggest challenges Semantic Web Services are facing. Finding a suitable way to put these two features together has become one ofthe key points to convert the Web in a distributed source of computation, as they enable the location and combination of distributed services to perform a required functionality.Automatic Web service discovery involves automatically locating Web Services that provide a particular functionality and that adhere to requested properties [11]. To provide such an automatic1 Semantic Web enabled Web Services. / location, the discovery process should be based on the semantic match between a declarative description of the service being sought, and a description of the service being offered. This problem requires not only an algorithm to match these descriptions, but also a language to declaratively express the capabilities of services [12].Furthermore, composition of Web Services requires something more than representing combinations of services where flow and bindings to the services are known a priori. It also must allow the combination of services to provide a given functionality when a request can not be fulfilled by using available services individually [15].Discovering and composing services needs an approach based on semantic descriptions, as the requester required functionally has to be expressed in a high-level and abstract way to enable reasoning procedures.Composition and discovery work together in different ways. The following examples depict different scenarios where location and combination of services take place:- A user wants to book a flight from Innsbruck to Madrid, for next Wednesday and with a fixed maximum price. With this information, discovery will look for a service accepting origin, destination, date and maximum price and providing a seat for an appropriate flight. In the case where such a service is not available, but only a service to look for flight information given trip data and another service to book a flight given flight information can be found, combination must be performed. By combining these two services, the requested functionality can be provided.- A travel agency models its business process to provide a “make a trip” service. The agency explicitly models control and data flow between the different services involved (book a flight, book a hotel, book a car…). In this case, composition is explicitly modeled at provider side. But in the situation where the agency does not want to limit the book flight service to a given company, a high-level description of the required service must be provided in the process model to enable dynamic discovery (and composition if not a single service can fulfill the requirements) of the best available service to book the flight based on requester criteria.These two examples illustrate the main roles of composition and discovery to provide a required functionality. Although these use cases can be modified and extended in a number of ways and different examples can be depicted, all of them rely on a high-level description of the functionality being sought.2.1Capability descriptionThe required high-level functionality description can be viewed as the capability of the service. Different services can provide the same capability, e.g., book a flight, and the same service can provide different capabilities, e.g., search a book and search a movie.In this sense, capabilities must be naturally described separately from specific service descriptions [8] for several reasons:- Express generic functionalities: Several services offering the same functionality but with different specific refinements should be related to the same generic high-level capability. Refinements can then be specified by different services. This approach is related to concepts taken from Problem Solving Methods research, and it inherits some of their advantages, as the ones highlighted in [7] and [9].- Use different terminologies: Refinements done by a given web service can be expressed using a different terminology from the one used to describe their capability, thus increasing flexibility, as requiring the use of the same terminology is sometimes unrealistic.- Allow a given service to present two different capabilities while exposing only one service description.- Support discovery process: Discovery first needs capability descriptions. Refinement based on actual input, output and requirements is performed in subsequent steps. Thus, separating capabilities and referring service refinements to them establishes a natural link to the discovery process.Declarative means to define capabilities, as well as specific service refinements and the link between refinements and capabilities are needed. This description must allow reasoning about the information presented by the service. Several works in the area use subsumption reasoning, i.e., determining whether a given concept is more general than another, to support discovery and composition, either looking for just one service providing the required functionality [12] or composing different services [2], like in the travel agency example exposed before.To support dynamic discovery and composition, a capability must include the following information:- Pre-conditions: High-level inputs to the service together with conditions over these inputs. These inputs are concepts of a given domain ontology. Each pre-condition will include an identifier to allow future references. High-level input means that more specific concepts in the ontology can be found, e.g. indicating payment information as a pre-condition, instead of credit card information or bank information or even data types. If a too specific concept is given as a pre-condition, then the capability will hardly express generic functionalities. It is important to notice that the pre-conditions of a given capability are not independent of each other, as they all define the functionality expressed in the capability.- Post-conditions: High-level results of the service execution together with conditions over these results. The results are also concepts of a given domain ontology. Identifiers are also defined for post-conditions, and as with pre-condition, they cannot be considered independent, as the removal of one of them changes the functionality expressed by the capability.- Textual description: To allow human interpretation.- Services: References to the services presenting the described capability.- Identifier: Identifier to allow references to the capability. Pre and post-conditions define the capability of the service in terms of the information needed to use the service and the results of its invocation. Describing capabilities by expressing their functionalities in terms of required high-level input and high-level results covers the following requisites:- Modeling a process at design time. In this case, the workflow and data flow is defined a priori, at least partially. Thus, the declaration of the use of a capability must enable the specification at design time of the input and the result of the service. This information is needed to model data and control flow. Nevertheless, this information must be kept general enough to describe generic service functionalities, allowing dynamic location and combination of services. For example, in a business process using a service to buy some goods and another service to ship them, the result of the buy_goods service must be used by the ship_goods service, and the required data and control flow must be designed. Other approaches like relating the capability to a task ontology describing possible requested functionalities cannot be used in this context, as they don’t provide enough information to define flow at design time.- Dynamic discovery: Subsumption algorithms, as the ones presented in [12] and [2] are supported by relating pre and post-conditions to the appropriate domain ontology and by using the specific services refinements, presented in the next subsection.- Dynamic composition: Combination of services to fulfill a given functionality can be performed by expressing functionality in terms of pre and post-conditions, as described in [2].- n to m mappings: Describing a capability using pre and post-conditions and not including low-level input and output information, enables n to m mappings between capabilities and services, thus allowing the description of generic functionalities and the declaration of different generic functionalities by the same service. Lower level inputs and outputs must not be included in the capability description as this would prevent these features and would imply several modeling problems, as explained in [14].Textual information is used to let the human user browse capabilities. Capabilities must be understandable by humans and machines [13], as a process designer may need to search suitable capabilities to include in a process model at design time. References to the services presenting the capability are specified to enable the location of refinements of the described generic functionality, i.e., the location of specific services during discovery and composition process.2.2Capability refinementsOnce a capability is described, different services presenting this capability can refine it. In this way, specific requirements, constraints and results of an individual service can be expressed. To avoid redundancy, the service will only explicitly describe the refinements it introduces, not repeating the information already enclosed in the capability description. Figure 1 depicts the relationship between capabilities and services:Figure 1. Relationship between capabilities and servicesBy defining the service refinements, a complete high-level description of the input required by the service and the result of its execution is given. Nevertheless, actual input and output data is needed to express the low-level details of service functionality. These inputs and outputs are naturally related to pre and post-conditions, as they constitute the realization in terms of data of high-level conditions.Therefore, the information to be exposed by an individual service to refine generic functionalities is the following:- Identifier: information for service references.- Textual description: human-understandable information.- Capability references: references to the capability or capabilities presented by the service.- Pre-condition refinements: pre-conditions refining the ones presented by the capability. If it is a refinement of one or more pre-conditions defined in the capability, a reference to them will be included. This is the case of a service referring to a capability requiring general payment information as pre-condition, while the service accepts only information about credit card. Also new pre-conditions are allowed, and identifiers for every new pre-condition or refinement must be included. In general, pre-condition refinements reflect the strengthening of pre-conditions. - Inputs: actual input data information. Inputs are grouped and referred to the pre-condition the group realizes, either from the generic capability or from the service refinements. To allow polymorphism, different sets of inputs can be defined for the same pre-condition. For example, in the case of a service accepting different ways of payment (credit card, bank transfer…), different input data is required depending on how the requester wants to pay. However, it is natural to define only one interface for the service. Therefore, this service will have a pre-condition “payment information”, with different sets of inputs associated to it for credit card payment, bank transfer payment, etc. Which specific set of inputs is used will be decided at run-time.- Post-condition refinements: refinements or new post-conditions. They are defined following the same mechanism as pre-conditions. Refinements of existing post-conditions reflect the weakening of the capability post-conditions, whereas adding new ones reflects the strengthening of the capability post-conditions- Outputs: actual output data, described in the same way as inputs.In figure 2 the refinement of pre-conditions and how the inputsrealize them is depicted:Figure 2. Pre-conditions refinements and pre-conditionsrealizationIn the figure above, service pre-condition 1 refines the first pre-condition defined in the capability. Inputs group 1 gives actual data for the refined pre-condition. Service pre-condition 2 is a new pre-condition, not existing in the capability exposed, and realized by inputs group 2. Capability pre-conditions 2 and 3 are not modified, so inputs groups 3 and 4 directly refer to these pre-conditions. As explained before, the refinement of more than one pre-conditions together is also possible.By defining capabilities, refinements and actual input and output data using appropriate ontologies, service description exposes enough information to enable automatic discovery and composition. Refinements and information about input and output data can also be used to locate a required service, as well as for composition, thus providing appropriate expressivity power for the requester. Therefore, the requester is not limited to locate and combine generic capabilities, but he can also express more detailed needs.2.3Relation to current technologiesAlthough the requirements presented above for describing service functionalities reflect the ideas contained in the WSMF approach, they extend and refine the description means outlined in the framework.Once these extensions and refinements are defined, they must be expressed using an appropriate ontology to provide semantics to the information exposed by the service. In this sense, neither BPEL4WS nor BPML/WSCI include any suitable mechanism, as they do not use similar concepts to capabilities or refinements and they do not add any semantic information.Therefore, DAML-S is the only potentially reusable work to define the desired ontology. The existing ontology of services, currently at version 0.9, includes profiles and service models, which purposes are similar to the ones of capabilities and refinements respectively. However, the DAML-S ontology presents serious limitations if left as it is. First, input and output is included in the profile, preventing polymorphism and n to m mappings between profiles and specific service models. Second, pre and post-conditions (pre-conditions and effects in DAML-S terminology) of the concrete service model are not related to the ones presented at the profile. Third, inputs and outputs are not related to pre-conditions and effects. Fourth, using different sets of inputs and outputs for a given pre or post-condition is not allowed. All these limitations imply service modeling problems, as analyzed in [14].In conclusion, the DAML-S ontology can be used as a basis to define semantics for service functionality descriptions, but it must be considerably changed and extended to present the properties and requirements presented in this section.3.Interoperation and current technologiesOne of the main purposes of web services is the automation of application integration within and across organizational boundaries. This implies necessarily the need for interoperation between services. This interoperation can be between services in an organization or crossing different organizational boundaries. To ensure automatic interoperation, description means must be defined declaratively using explicit semantics.Business collaborations require long-running interactions driven by an explicit process model [17]. Thus, a service must explicitly model its business process which will contain decision mechanisms for the execution of the service. But following one of the main principles of WSMF, no internal details of the organization business logics should be made publicly visible. Therefore, while a process model and its data and control flow must be designed explicitly to ground the execution and public behavior of a given service, it must not be exposed. Nevertheless, the external behavior of the service in terms of message interchange must be made public in order to enable automatic interoperation of the service with any other service. In this sense, the public description of a service must include a conversational interface which allows interoperation while not revealing any private detail.Figure 3 illustrates the relationship between the private process model and the public process model in terms of visibility. Private process model grounds the public model and drive its actualbehavior, but only the public process model is made public.Figure 3. Public and private process models visibility2 Although the main purpose of this paper is to define public description requirements for semantic web services, private process modelling deserves some analysis given its close relationship with public process models.Concerning private process models, both BPEL4WS and BPML offer a rich set of primitives to model the workflow of the service, supporting composite processes based on web services. In [19] and [16] a pattern based analysis of both languages can be found. This work analyzes BPEL4WS and BPML/WSCI using a set of workflow and communication patterns to clarify if they provide sufficient modeling primitives for any possible abstract situation. The result is similar for both, as they support most of the patterns described, either directly or using workarounds.Both approaches clearly separate private and public process models. BPEL4WS introduces the concept of executable process for private processes and abstract process for public processes. Similarly, BPML is used to model private processes while WSCI is concerned with the choreography and public interoperation of services. However, as stated before, both languages lack semantics to expose its public interface as well as the possibility of expressing the use of a service within the private process model in terms of the capability it presents.DAML-S must be analyzed for this purpose, as it is the only initiative including explicit semantics. However, an appropriate service ontology requires a richer set of process modeling primitives, as the concepts described in the DAML-S process model are not powerful enough to support some of the communication and workflow patterns required. And what is more, DAML-S does not distinguish between private and public processes, allowing internal details to be exposed via a composite process. Thus, although DAML-S provides ontological support for service modeling, its limitations prevent his direct use to publish interoperation information.Our proposal is to add semantics to either BPEL4WS or BPML/WSCI modelling mechanism for conversational interface 2 From the presentation “Principles of integration: Are Web Services heading in the right direction?”, Christoph Bussler, Innsbruck 19.05.2003and integrate these semantics into the service ontology. That means replacing the process model in DAML-S by a BPEL4WS or BPML/WSCI-based model, including the necessary public information to expose the behaviour of the service in terms of message interchange.Summarizing, the public description requirements for interoperation, which will be grounded in the way previously discussed, are the following:- External behavior of the service in terms of message interchange and message sequencing must be described.- No information about internal business logics should be exposed.- The public process exposed must be grounded by an appropriate private process, which must allow the use of capabilities and refinements at design time to specify the service to be used and its dynamic location and composition.Deciding whether BPEL4WS or BPML/WSCI can be used to fulfill these requirements is out of the scope of this paper. In any case, they must be semantically grounded and extended to use generic capabilities and refinements at design time in the way described in the previous section, and included in the service ontology with the necessary extensions.Also the use of Abstract State Machines (ASMs) [3] to model business processes is being analyzed, as they present several interesting properties, namely: express functionally complete but abstract description that can be understood by a human reader, define every system features as far as it is semantically relevant for the required functionality and contain only what the logic of the problem requires for the system behavior. Furthermore, the grounding model is implemented following a refinement process, trough a hierarchy of intermediate models, and ASMs also allow structuring the system horizontally by building it from components with abstract definitions of behavior and interactions trough interfaces.Though ASMs properties make them suitable for its use to describe service conversational interfaces and their corresponding groundings, none of current efforts use ASMs. As this paper tries to ground description requisites using existing technologies or extensions and combinations of them, introducing ASMs is out of the scope of this paper, although it will be part of future work.4.Service invocationThe requirements presented so far deal with the expression of declarative functionality and the publication of conversational interface. This information will support discovery, composition and interoperation, but declarative means to enable invocation of a given service are still missing in the picture.Invocation information presented by a given service must be agnostic in principle with respect to the specific technologies which will ground it. Nevertheless, details must be available at run-time for the service requester in order to perform a real invocation. These details must relate every aspect of the declared functionality to a ground mechanism, e.g., SOAP on HTTP. Grounding mechanisms are provided within BPEL4WS, BPML/WSCI and DAML-S, although most of the examples available are focused on WSDL and SOAP grounding. Considering the need for an effective and platform independent invocation, input and output data, messages and message sequencing must be declaratively related to a specific technology and exposed in the public service description. In this sense, service ontology must include concepts to express this relationship, as the “grounding” concept defined in DAML-S ontology.Due to the semantic link to the required grounding, DAML-S should naturally be used as a starting point as it already contains a declarative grounding mechanism [6]. Nevertheless, the DAML-S ontology relates grounding directly to a given service, hence not supporting polymorphism and encountering problems while grounding a real service, as the ones highlighted in [14]. As a consequence, extensions to DAML-S grounding mechanism are to be introduced in order to support the grounding of the description means introduced in sections 2 and 3. Different groundings for every set of inputs must be defined, and the use of a concrete grounding should be decided at run-time. Furthermore, conversational interface, not defined in DAML-S ontology, must be related in a similar way to a concrete technology.However, the basic DAML-S grounding mechanism can be reused and refined make it usable for automatic invocation. After the outlined refinements are performed, services presenting all the properties required in this paper can be grounded using such ontology.pensation and other requirementsUntil now, the optimistic assumption “everything works well” has been implicitly made. No errors were considered, although they appear in computer systems more frequently than desired. Due to this fact, an intelligent service description must take into account possible errors and how to deal with them.For this purpose, error data must be described in addition to input and output data. A SWS description should include one or more error ports, to provide error information to the requester potentially at different points of execution. These error ports must refer to an appropriate ontology in the same way inputs and outputs do. Error ports can be thought as special types of outputs, so the same requirements apply to them, although they are not referred to any pre or post-condition. Error ports, as well as inputs and outputs, will be used in the same way in the definition of the conversational interface, establishing at which point of execution a concrete input is required, when outputs are delivered to the requester, and where specific error ports may report error information. These ports will also be included in the service grounding information.In the context of semantic web services, dynamic location and combination of services implies that no a priori assumptions can be made about the duration of a service invocation. For this reason, the use of traditional ACID transactions [10] to deal with errors is not useful in this context, as they require blocking resources for an undefined amount of time. Therefore, the concept of compensation has appeared to substitute classic transactions. Compensating a service means to invoke one or more services to undo the actions of the former one. For instance, a service to book。

学术英语写作Unit-5----Abstract

学术英语写作Unit-5----Abstract
Unit 5 Abstract
What is an abstract? Types of abstracts Why write an abstract? What should the abstract include? How do you write an abstract? What is the style of an abstract? An outline for writing an abstract Common problems in writing an abstract Difference between an abstract and an introduction The Tricks, Conclusion of the lecture
Informative abstracts资料性摘要
The informative abstract, also known as the complete abstract, is a compendious summary of a paper's substance including its background, purpose, methodology, results, and conclusion. Usually between 100 and 200 words, the informative abstract summarizes the paper's structure, its major topics and key points. A format for scientific short reports that is similar to an informative abstract has been proposed in recent years. Informative abstracts may be viewed as standalone documents.

Java中的abstract方法和abstract类的问题

Java中的abstract方法和abstract类的问题
如何扩展这些设计呢?譬如说为Triangle和Circle添加erase方法?
如果是class Shape这样的设计,很简单,只要
abstract class Shape{
puabstract void reDraw();
public void erase(){
window.clean();
}
}
所有相关的代码,你都要修改!即便他们都做同样的事情!
这样扩展实在是太麻烦了!
你也许和我想的一样,定义接口本身的目的就是告诉大家,任何实现此接口的类,都有自己的实现方法!
我们定义接口的目的是:你们的实现可以不一样,但是你们暴露的接口一定要一致
可以举java类库当中的一个设计,Thread
public void reDraw(){...}
}
只不过现在子类Triangle,Circle和Shape之间的关系就不是父子了。
这样设计其实违背了常理,因为在我们的观念中,Triangle和Circle本来就应该是一种Shape
而不应该是他们都遵守一定的操作方式(void draw(),void reDraw())
abstract修饰符用来修饰类和成员方法
1:用abstract修饰的类表示抽象类,抽象类位于继承树的抽象层,抽象类不能被实例化。
2:用abstract修饰的方法表示抽象方法,抽象方法没有方法体。抽象方法用来描述系统具有什么功能,但不提供具体的实现。
abstract规则:
1:抽象类可以没有抽象方法,但是有抽象方法的类必须定义为抽象类,如果一个子类继承一个抽象类,子类没有实现父类的所有抽象方法,那么子类也要定义为抽象类,否则的话编译会出错的。
2.在设计的时候就应该认识到,实例化Shape是没有意义的,因为Shape本身只是一种抽象。现在别人如果拿来就可以实例化了,这样的操作方式违背了当初设计的意愿。而且会存在潜在的危险。(当前的实现可能看不出危险)

非酒精性脂肪性肝病患者外周血内皮素、C型凝集素-1水平与小肠细菌过度生长、肝纤维化的关系

非酒精性脂肪性肝病患者外周血内皮素、C型凝集素-1水平与小肠细菌过度生长、肝纤维化的关系

·论著·非酒精性脂肪性肝病患者外周血内皮素、C型凝集素-1水平与小肠细菌过度生长、肝纤维化的关系王青青魏芳刘莹莹李立文张秀刚【摘要】目的探究非酒精性脂肪性肝病(NAFLD)患者外周血内皮素(ET)、C型凝集素-1(Dectin-1)水平与小肠细菌过度生长(SIBO)、肝纤维化的关系。

方法选择2021年10月至2022年10月沧州市中心医院收治的88例NAFLD患者作为研究对象(设为NAFLD组),另选择同期在该院体检的65名健康体检者作为对照组。

采用ELISA法检测受试者血清ET和Dectin-1水平。

采用Pearson相关系数法分析NAFLD患者外周血ET、Dectin-1水平与SIBO的相关性。

采用ROC曲线分析外周血ET、Dectin-1水平对NAFLD患者肝纤维化的评估价值。

结果与对照组相比,NAFLD组的SIBO阳性率及血清ET、Dectin-1水平均显著升高,差异均有统计学意义(P均<0.001)。

与SIBO阴性组相比,SIBO阳性组的乳果糖氢呼气试验(LHBT)集值及血清ET、Dectin-1水平均显著升高,差异均有统计学意义(P均<0.001)。

Pearson相关性分析结果显示,NAFLD组血清ET、Dectin-1水平与LHBT集值均呈正相关(r=0.552,P<0.05;r=0.451,P<0.05)。

与对照组相比,无肝纤维化组、轻度肝纤维化组和重度肝纤维化组的血清ET、Dectin-1水平均显著升高,且随肝纤维化程度加重,血清ET、Dectin-1水平随之升高(P均<0.05)。

ROC曲线分析结果显示,血清ET、Dectin-1水平评估NAFLD患者肝纤维化的最佳截断值分别为65.63 pg/mL、18.52 pg/mL。

血清ET和Dectin-1联合检测评估NAFLD患者肝纤维化的曲线下面积(AUC)均大于单项检测,差异均有统计学意义(P均<0.05),且联合检测的特异度较高。

2012-HCI-MA-H2-P1-Prelim


(i)
f :x→
kx 2 − 5 x + 3 , x−2
(ii) (iii)
Use the standard series for ln(1 + x ) to find the first three terms of the 1 Maclaurin's series for y = . [3] 1 + ln (1 + 2 x )
One NETO logistics commander was tasked to deliver goods to an army camp in Abghan during June 2012. The commander delivered 1000 tons of goods on 1st June, 1100 tons on 2nd June, ... etc. Each subsequent day’s delivery was 100 tons more than the previous day’s delivery. After several days of delivery, due to more road attacks from Bl Paeda, the commander had to change the plan so that each subsequent day’s delivery was 100 tons less than the previous day’s delivery. By 15th June, the commander managed to deliver a total of 21300 tons of goods for the past 15 days. On which day did the commander deliver the most goods to the camp? How many tons of goods did he deliver on this particular day? [5] Given that all terms in a geometric progression {un } , n = 1, 2, 3, ... are positive with first term a and common ratio r, where r ≠ 1, the sums H and C are defined as follows:

ABSTRACT

Bringing Practical Lock-Free Synchronization to64-BitApplicationsSimon DohertySchool of Mathematical and Computing SciencesVictoria UniversityWellington,New Zealandsimon.doherty@Maurice Herlihy Department of Computer Science Brown UniversityProvidence,RI02912,USAmph@Victor LuchangcoSun Microsystems Laboratories1Network Drive Burlington,MA01803,USA victor.luchangco@Mark MoirSun Microsystems Laboratories 1Network Drive Burlington,MA01803,USAmark.moir@ABSTRACTMany lock-free data structures in the literature exploit tech-niques that are possible only because state-of-the-art64-bit processors are still running32-bit operating systems and applications.As software catches up to hardware,“64-bit-clean”lock-free data structures,which cannot use such tech-niques,are needed.We present several64-bit-clean lock-free implementations: load-linked/store-conditional variables of arbitrary size,a FIFO queue,and a freelist.In addition to being portable to 64-bit software,our implementations also improve on previ-ous ones in that they are space-adaptive and do not require knowledge of the number of threads that will access them. Categories and Subject DescriptorsD.1.3[Programming Techniques]:Concurrent Program-ming;D.4.2[Operating Systems]:Storage Management;E.1[Data]:Data StructuresGeneral TermsAlgorithms,TheoryKeywordsMultiprocessors,64-bit architectures,64-bit-clean software, nonblocking synchronization,lock-free,memory management, population-oblivious,space-adaptive,compare-and-swap(cas), load-linked/store-conditional(ll/sc),queues,freelists1.INTRODUCTIONFor more than a decade,64-bit architectures have been available[14,16,18,21].These architectures support64-bit addresses,allowing direct access to huge virtual address PODC’04,July25–28,2004,St.John’s,Newfoundland,Canada.Copyright2004Sun Microsystems,Inc.All rights reserved.ACM1-58113-802-4/04/0007.spaces[3].They also support atomic access to64-bit quanti-ties using synchronization primitives such as compare-and-swap(cas)and the load-linked/store conditional(ll/sc) pair,which provide powerful tools for implementing lock-free data structures.Predictably,operating systems and application software that exploit these64-bit capabilities have been slower to emerge.Thus,many important32-bit operating systems and applications are still in common use,and most64-bit ar-chitectures support them.As a result,for a period of several years,techniques that use64-bit synchronization primitives to atomically manipulate32-bit pointers together with other information,such as version numbers,have been widely ap-plicable.Many practical lock-free data structures exploit such techniques(e.g.,[13,19]).The increasing prevalence of64-bit operating systems and applications(in which pointers are64bits)signals the end of this convenient era:64-bit-clean lock-free data struc-tures that do not require synchronization primitives that can atomically manipulate a pointer and a version number are increasingly important.We present64-bit-clean1implementations of several im-portant lock-free data structures:arbitrary-size variables supporting ll and sc operations,FIFO queues,and freelists. Our implementations are based on64-bit cas,but it is straightforward to modify them for use in architectures that support ll/sc instead of cas[15].Our ll/sc implemen-tation is useful even in architectures that provide ll/sc in hardware,because it eliminates numerous restrictions on the size of variables accessed by ll/sc and the way in which they are used.For example,in some architectures,the program must perform only register operations between an ll and the following sc;no such restriction is imposed by our imple-mentation.Our results therefore will help programmers to develop portable code,because they can ignore the different restrictions imposed by different architectures on the use of 1Our techniques target any architecture that can perform cas on a pointer-sized variable(of at least64bits);for con-creteness,we present our techniques assuming that this size is64bits.ll/sc.Furthermore,our implementations are portable be-tween32-bit and64-bit applications,while many previouslock-free data structure implementations are not.The only previous64-bit-clean cas-based implementationof ll/sc is due to Jayanti and Petrovic[10].While their im-plementation is wait-free[5],it requires O(mn)space,wherem is the number of variables that support ll/sc and n is the number of threads that can access those variables;oursuses only O(m+n)space.Furthermore,the implementationin[10]requires a priori knowledge of afixed upper boundon the number of threads that will access an ll/sc vari-able.We call such implementations population-aware[8].In contrast,our implementation has no such requirement;itis population-oblivious.However,our implementation guar-antees only lock-freedom,a weaker progress guarantee thanwait-freedom,but one that is generally considered adequatein practice.Our lock-free FIFO queue implementation is thefirst thatis64-bit-clean,population-oblivious and space-adaptive(i.e.,its space consumption depends only on the number of itemsin the queue and the number of threads currently accessingthe queue).Previous lock-free FIFO queue implementationshave at most one of these advantages.A freelist manages memory resources and can be used toavoid the cost of using a general malloc/free implementationfor this purpose.Previous lock-free freelists[19]are not64-bit-clean,and can be prevented by a single thread failurefrom ever freeing memory blocks to the system.Ours over-comes both of these problems.We provide some background in Section2,and present ourll/sc implementation in detail in Section3.In Sections4 and5,we explain how to adapt the techniques used in the ll/sc implementation to achieve our queue and freelist im-plementations We conclude in Section6.2.BACKGROUNDA data structure implementation is linearizable[9]if for each operation,there is some point—called the linearization point—during the execution of that operation at which the operation appears to have taken place atomically.It is lock-free[5]if it guarantees that after afinite number of steps of any operation on the data structure,some operation com-pletes.It is population-oblivious[8]if it does not depend on the number of threads that will access the data structure. Finally,it is space-adaptive if at all times,the space used is proportional to the size of the abstract data structure(and the number of threads currently accessing it).2The cas operation,defined in Figure1,takes the address of a memory location,an expected value,and a new value. If the location contains the expected value,then the cas atomically stores the new value into the location and re-turns true.Otherwise,the contents of the location remain unchanged,and the cas returns false.We say that the cas succeeds if it returns true,and that it fails if it returns false.A typical way to use cas is to read a value—call it A—from a location,and to then use cas to attempt to change the location from A to a new value.The intent is often to ensure that the cas succeeds only if the location’s value does not change between the read and the cas.However,the lo-cation might change to a different valueB and then back 2There are other variants of space adaptivity[8],but this simple definition suffices for this paper.bool cas(a,e,n){atomically{if(∗a==e){∗a=n;return true;}elsereturn false;}Figure1:The CAS operation.to A again between the read and the cas,in which case the cas can succeed.This phenomenon is known as the ABA problem[17]and is a common source of bugs in cas-based algorithms.The problem can be avoided by storing the variable being accessed together with a version number in a cas-able word:the version number is incremented with each modification of the variable,eliminating the ABA prob-lem(at least in practice;see[15]for more detail).However, if the variable being modified is a64-bit pointer,then this technique cannot be used in architectures that can perform cas only on64-bit variables.A key contribution of this pa-per is a novel solution to the ABA problem that can be used in such architectures.The ll and sc operations are used in pairs:An sc op-eration is matched with the preceding ll operation by the same thread to the same variable;there must be such an ll operation for each sc operation,and no ll operation may match more than one sc operation.ll loads the value of a location,and sc conditionally stores a value to a location, succeeding(returning true)if and only if no other store to the location has occurred since the matching ll.3Thus the ABA problem does not arise when using ll and sc—instead of read and cas—to modify a variable.For simplicity,we require every ll to be matched.If a thread decides not to invoke a matching sc for a previous ll,it instead invokes unlink,which has no semantic effect on the variable.An ll operation is said to be outstanding from its linearization point until its matching sc or unlink returns.It is straightforward to eliminate the need for an explicit thread-visible unlink operation by having ll in-voke unlink whenever a previous ll operation by the same thread to the same location is already outstanding. Related workAnderson and Moir[2]describe a wait-free implementation of a multiword ll/sc that requires O(mn2)space,where m is the number of variables and n is the number of threads that may access the variables;Jayanti and Petrovic present another that uses O(mn)space[10].These algorithms are impractical for applications that require ll/sc on many vari-ables.In addition,they are not population-oblivious;they require n to be known in advance,a significant drawback for applications with dynamic threads.Moir[15]presents a lock-free algorithm that uses only O(m)space,but his algorithm is not64-bit-clean.Our queue algorithm is similar to the algorithms of Val-ois[20]and of Michael and Scott[13].However,those algo-rithms are not64-bit-clean.Furthermore,they cannot free nodes removed from the queue for general reuse(though the 3We describe the ideal ll/sc semantics here.Hardware ll/sc implementations are usually weaker;in particular, they allow sc to fail even in the absence of an intervening store[15].nodes can be reused by subsequent enqueue operations),and are therefore not space adaptive.Herlihy et al.[7]and Michael[11]independently proposed general techniques to enable memory to be freed from lock-free data structures,and they applied these techniques to the Michael-and-Scott queue[6,11].However,the resulting algorithms are not population-oblivious.Although they can be made population-oblivious[8],the resulting solutions are still not space adaptive;in the worst case,they require space proportional to the number of all threads that ever access the queue.Treiber[19]provides two freelist implementations,neither of which is64-bit-clean.Furthermore,thefirst does not provide operations for expanding and contracting the freel-ist.Modifying the implementation to expand the freelist is straightforward,but enabling contraction is not.Treiber’s second freelist implementation does allow contraction,but a single delayed thread can prevent all contraction.In con-trast,our freelist implementation is64-bit-clean and does not allow thread delays to prevent other threads from con-tracting the freelist.3.OUR LL/SC IMPLEMENTATIONWith unbounded memory,it is straightforward to imple-ment a lock-free,population-oblivious,arbitrary-sized ll/sc variable using the standard pointer-swinging technique:We store values in contiguous regions of memory called nodes and maintain a pointer to the current node.ll simply reads the pointer to the current node and returns the contents of the node it points to.sc allocates a new node,initializes it with the value to be stored,and then uses cas to attempt to“swing”the pointer from the previously current node to the new one;the sc succeeds if and only if the cas succeeds. If every sc uses a new node,then the cas in an sc succeeds if and only if there is no change to the pointer between the cas and the read in the preceding ll.This technique is well-known and used in systems that use garbage collection to provide the illusion of unbounded memory(see the JSR-166 library[1],for example).Our implementation builds on this simple idea,but is com-plicated by the need to free and reuse nodes in order to bound memory consumption.Reclaiming nodes too late re-sults in excessive space overhead.However,reclaiming them too soon leads to other problems.First,an ll reading the contents of a node might in fact read part or all of a value stored by an sc that is reusing the node.Second,the cas might succeed despite changes since the previous read be-cause of the recycling of a node:the ABA problem.Our im-plementation maintains additional information that allows nodes to be reclaimed promptly enough to bound its space complexity,but avoids the problems above by preventing premature reclamation.Wefirst describe the basic implementation assuming that nodes are never reclaimed prematurely and ignoring those parts related only to node reclamation(Section3.1).Then we describe how nodes are reclaimed,argue why they are never reclaimed prematurely,and analyze the space com-plexity of the algorithm(Section3.2).To simplify the code and discussion,the implementation presented here restricts threads to have at most one outstanding ll operation at a time.However,extending it to allow each thread to have multiple outstanding ll operations is straightforward.typedef struct{Node∗ptr0,∗ptr1;EntryTag entry;}LLSCvar;typedef struct{Data d;Node∗pred;ExitTag exit;}Node;typedef struct{int ver;int count;}EntryTag;typedef struct{int count;bool nlC;bool nlP;}ExitTag;Figure2:Data types used in the LL/SC algorithm. The EntryTag and ExitTag typesfit into64bits,so can be atomically accessed using cas.3.1The basic implementationRather than storing a pointer to the current node in a single location,we alternate between two locations,ptr0 and ptr1.At any time,one of these pointers is the current pointer—it points to the current node—and the other is the noncurrent pointer.Which pointer is current is determined by a version number entry.ver:4if entry.ver is even,then ptr0is the current pointer;otherwise ptr1is.An ll operation determines the current node and returns the data value it contains.An sc operation attempts to change the noncurrent pointer to point to a new node—initialized with the data value to be stored—and then in-crement entry.ver,making this pointer current.If the sc successfully installs the new pointer but is delayed before incrementing the version number,then another thread can “help”by incrementing the version number on its behalf. The successful sc is linearized at the point at which the ver-sion number is incremented(either by the thread executing that sc or by a helping thread),causing the newly installed node to become current.Our algorithm guarantees the following alternating prop-erty:In any execution,the sequence of events that modify ptr0and ptr1and entry.ver strictly alternates between •modifying the noncurrent pointer to point to the new node of an sc operation;and•incrementing entry.ver,thereby causing the current pointer to become noncurrent and vice versa.With this property,it is easy to see that the algorithm de-scribed above provides the correct semantics:neither ptr0 nor ptr1ever changes while it is the current pointer;the noncurrent pointer is changed exactly once(by a successful sc operation)between consecutive increments of entry.ver; and each time we increment the version number,and there-fore linearize a successful sc(the unique sc that changed the noncurrent pointer since the previous time the version number was incremented),the new node installed by the successful sc becomes the current node.Figure2shows the types used in our implementation.An LLSCvar structure consists of threefields,ptr0,ptr1and 4In addition to determining which pointer is current,the version number eliminates the ABA problem in practice, provided the version number has enough bits to ensure that it does not repeat a value during the interval in which some thread executes a short code sequence.In our algorithm,we can easily allocate32or more bits to the version number, which we believe is sufficient.For further discussion of the number of bits required to avoid the ABA problem,see[15].ptr0→d=d0entry.ver=0ptr0→pred=ptr1entry.count=0ptr0→exit= 0,false,falseptr1→exit= 0,true,falseFigure3:Initial state of an LL/SC location,where d0is the initial value of the location.(a)(b)Figure4:Two states of the LL/SC implementation. Dotted pointer indicates previous value(see text). entry,each of which is64bits(so the cas operation can be applied to eachfield,though not to the entire LLSCvar structure).In addition to thefields already mentioned,the entryfield of an ll/sc variable has a countfield,and each node has pred and exitfields.The predfield of each node contains a pointer to the node that was current immediately before this node.The otherfields are concerned only with node reclamation,and are discussed later.Figure3shows how an ll/sc variable is initialized and Figure4illustrates two classes of states of our algorithm.In both illustrations,entry.ver is odd,so ptr1is the current pointer and ptr0is the noncurrent pointer.In Figure4(a), the noncurrent pointer points to the current node’s prede-cessor(i.e.,the node that was current before the node that is current in thefigure).In Figure4(b),the noncurrent pointer points to a new node whose predfield points to the current node.From a state like the one in Figure4(a),installing a pointer to a new node whose predfield points to the cur-rent node into the noncurrent pointer results in a state like the one in Figure4(b).Furthermore,from a state like the one in Figure4(b),incrementing entry.ver results in a state like the one in Figure4(a),because incrementing entry.ver changes its parity,thereby reversing the roles of ptr0and ptr1.The key to understanding our algorithm is to notice that it alternates between states like that in Figure4(a)and states like that in Figure4(b).This behavior is captured by the alternating property,which is central to the correctness proof for our algorithm.We now present our algorithm in more detail and explain how it preserves the alternating property;we ignore for now details related to node reclamation.Pseudocode for the ll, sc and unlink operations is presented in Figure 5.Each thread has two persistent local variables,mynode and myver, which are set by the ll operation,and retain their values while that ll is outstanding.The CURRENT and NONCURADDR macros determine the current and noncurrent pointers based on the ptr0or ptr1fields and the entry.verfields,as ex-plained above.Specifically,if loc→entry.ver==version, then CURRENT(loc,version)gives the current pointer of loc, and NONCURADDR(loc,version)gives the address of the non-current pointer.The release and transfer procedures, the entry.countfield,and the exitfield and its initializa-tion value INIT EXIT are relevant only to node reclamation, as are the effects of unlink.We defer further discussion of these procedures andfields until Section3.2.Ignoring for now the effect of the cas at line L5on the entry.countfield,we see that a thread p executing ll records entry.ver in its persistent local myver variable and the cur-rent node indicated by this value in its mynode variable.To ensure a consistent view of the current node and version number,ll retries if entry.ver changes while it determines the current node(lines L2and L5).The ll operation is linearized at the(unique)point at which p successfully exe-cutes the cas at line L5.To execute an sc operation,p allocates and initializes a new node5with the value to be stored,and stores the node observed as current by the previous ll in the node’s pred field(lines S1and S2).Then,p uses cas to attempt to change the noncurrent pointer to point to the new node(line S4).We do not simply read the contents of the noncurrent pointer in order to determine the expected value for this cas. If we did,two different sc operations could install new nodes in the noncurrent pointer,without the noncurrent pointer becoming current as the result of an increment of entry.ver. Such behavior would violate the alternating property.To avoid this problem,we instead determine the expected value for the cas by reading the predfield of the node ob-served as current(line S3).Recall that when a node becomes current,its predfield points to the node that was current im-mediately before it.Thus,the predfield of the current node is the same as the noncurrent pointer before a new node is installed.Once an sc has successfully changed the noncur-rent pointer to point to a new node,no other sc can do so again before entry.ver is incremented.This could happen only if some thread previously saw the newly installed node as the predecessor of some node.As we explain later,our node reclamation technique precludes this possibility.After the execution of line S4,either p’s sc has succeeded in changing the noncurrent pointer,or some other sc has.In either case,the entry.verfield should now be incremented in order to make the successful sc that installed a new node take effect.The cas at line S7ensures that the version number is incremented.(The loop at lines S6through S8 is necessary because the cas at line S7may fail for reasons other than another thread having incremented entry.ver; this possibility is explained below.)3.2Memory reclamationIf nodes are never reclaimed,then values stored to ptr0 and ptr1are all distinct,and it is easy to see the correct-ness of the algorithm as described.We now explain how our implementation reclaims and reuses nodes and why the algorithm is correct despite this.For simplicity,we defer consideration of unlink until later in this section;for now, we assume that every ll is matched by an sc.After an ll successfully executes the cas at line L5,it reads the contents of the node it determined to be current at lines L6and S3.We ensure that the node is not reclaimed before this happens.Specifically,after a thread successfully executes the cas at line L5,we ensure that the node is not 5If no suitable lock-free memory allocator is available,then nodes can be allocated from a freelist.The implications of this approach are described in Section3.3.Macros:CURRENT(loc,ver)≡(ver%2==0?loc→ptr0:loc→ptr1) NONCURADDR(loc,ver)≡(ver%2==0?&loc→ptr1:&loc→ptr0) INIT EXIT≡ 0,false,falseData ll(LLSCvar∗loc){L1.do{L2.EntryTag e=loc→entry;L3.myver=e.ver;L4.mynode=CURRENT(loc,e.ver);L5.}while(!cas(&loc→entry,e, e.ver,e.count+1 ));L6.return mynode→d;}void unlink(LLSCvar∗loc){U1.while((e=loc→entry).ver==myver)U2.if(cas(&loc→entry,e, e.ver,e.count−1 ))return; U3.release(mynode);}bool sc(LLSCvar∗loc,Data newd){S1.Node∗new nd=alloc(Node);S2.new nd→d=newd;new nd→pred=mynode;new nd→exit=INIT EXIT;S3.Node∗pred nd=mynode→pred;S4.success=cas(NONCURADDR(loc,myver),pred nd,new nd); S5.if(!success)free(new nd);S6.while((e=loc→entry).ver==myver)S7.if(cas(&loc→entry,e, e.ver+1,0 ))S8.transfer(mynode,e.count);S9.release(mynode);S10.return success;}Figure5:The LL,SC,and UNLINK operations.Macros:CLEAN(exit)≡(exit.count==0∧pre.nlC)FREEABLE(exit)≡(CLEAN(exit)∧exit.nlP)void release(Node∗nd){R1.Node∗pred nd=nd→pred;R2.do{R3.ExitTag pre=nd→exit;R4.ExitTag post= pre.count−1,pre.nlC,pre.nlP ; R5.}while(!cas(&nd→exit,pre,post));R6.if(CLEAN(post))setNLPred(pred nd);R7.if(FREEABLE(post))free(nd);}void transfer(Node∗nd,int count){T1.do{T2.ExitTag pre=nd→exit;T3.ExitTag post= pre.count+count,true,pre.nlP ; T4.}while(!cas(&nd→exit,pre,post));}void setNLPred(Node∗pred nd){P1.do{P2.ExitTag pre=pred nd→exit;P3.ExitTag post= pre.count,pre.nlC,true ;P4.}while(!cas(&pred nd→exit,pre,post));P5.if(FREEABLE(post))free(pred nd);}Figure6:Helper procedures for the LL/SC implementation.reclaimed before that thread invokes release on that node at line S9.Also,to avoid the ABA problem,we ensure that a node is not reclaimed if some thread might still see it as the predecessor of another node(at line S3),and therefore use it as the expected value for the cas at line S4.We avoid both premature reclamation scenarios by record-ing information in entry.count and the exitfield of each node that allows us to determine when it is safe to re-claim a node.First,we use entry.count to count the num-ber of threads that successfully execute the cas at line L5 while entry.ver contains a particular value.(Note that entry.count is reset to zero whenever entry.ver is incre-mented at line S7.)When a thread increments entry.count, we say the thread pins the node that is current at that time. One might think that we could maintain an accurate count of the number of threads that have pinned a node and not subsequently released it by simply decrementing entry.count in release.However,this approach does not work because by the time a thread invokes release for a particular node, that node is no longer current,so entry.count is being used for a different node—the one that is now current.There-fore,we instead use a node’s exit.countfield to count the number of threads that have released the node;this counter starts at zero and is decremented by each releasing thread (see lines R4and R5in Figure6).We use the transfer procedure to reconcile the number of threads that pinned the node with the number that have since released it.transfer adds the value of entry.count when a node is replaced as the current node to that node’s exit.countfield(lines S7,S8,and T1through T4).When exit.count contains zero after this transfer has happened, all threads that pinned this node have since released it.To distinguish the initial zero state of the exit.countfield from the state in which entry.count has been transferred and all threads have executed release,we use aflag nlC in the node’s exitfield;transfer sets exit.nlC(see line T3)to indicate that the transfer has occurred(nlC stands for“no longer current”;transfer is invoked by the thread that makes the node noncurrent).We say that a node with exit.nlC set and exit.count==0is clean(as captured by the CLEAN macro).For the unlink operation,a thread could simply invoke release,as on line U3.However,if entry.ver has not changed since the thread pinned a node,we can instead decrement entry.count(see lines U1and U2);it is still being used to keep track of the number of threads that pinned the node pinned by the thread that invoked unlink.In our algorithm as described so far,no thread accesses a clean node.However,it is not always safe to free a clean node:recall that we must also prevent a node from being reclaimed while a thread might still determine it to be the predecessor of another node.For this purpose,we use one moreflag in the exitfield called nlP(for“no longer prede-cessor”).At any time,each node is the predecessor of only one node,so we simply need to determine when that node’s predfield will no longer be accessed by any thread,that is, when that node is clean.A thread that makes a node clean invokes the setNLPred procedure to set the nlPflag of thenode’s predecessor(line R6).When a node is clean and has its exit.nlPflag set,as expressed by the FREEABLE macro, it is safe to free the node(lines R7and P5).Let us analyze the space requirements for an application using our implementation for ll/sc variables.Each variable requires O(1)space for its LLSCvar structure,and has two nodes that cannot be reclaimed(the nodes pointed to by its ptr0and ptr1fields).In addition,each ll/sc sequence in progress can prevent the reclamation of three nodes:the node pinned by the thread between an ll operation and its matching sc or unlink,the predecessor of the pinned node, and the new node used by an sc operation.Thus,in an application with m ll/sc variables,the space used by our algorithm at any time is O(m+k),where k is the num-ber of outstanding ll operations at that time.In the worst case,when all n threads have outstanding ll operations,the space used is O(m+n).Note that this space complexity is asymptotically optimal,and that the space used adapts to the number of threads actually accessing the ll/sc variables at any time.In particular,only O(m)space is needed when no threads are accessing these variables.The only previous 64-bit-clean implementation[10]always uses O(mn)space, a clear limitation in practice.Furthermore,it requires a priori knowledge of n;our algorithm does not.3.3Optimizations and ExtensionsOur ll/sc implementation can be made more efficient by observing that if FREEABLE(post)holds before the cas on line R5or line P4,then the cas does not need to be executed; mynode can simply be freed because there are no threads that still have to release this node.Similarly,a thread that calls transfer at line S8will always subsequently call release at line S9.Therefore,we can combine the effect of the two cas es in those two procedures into a single cas.It is easy to extend our implementation to allow threads to have multiple outstanding ll operations:each thread simply maintains separate mynode and myver local variables for each outstanding ll.In the resulting extension,a thread may pin several nodes simultaneously(one for each outstanding ll). The space complexity of this extension is still O(m+k), but now there may be more outstanding ll operations than threads(i.e.,we may have k>n).In the unlikely case that all n threads simultaneously have outstanding ll operations on all m variables,then O(mn)space is used.However, this much space is used only while O(mn)ll operations are outstanding.As before,if no threads are accessing the ll/sc variables,then the space consumed is O(m).We can also extend our implementation to provide an operation that“validates”the previous ll,that is,deter-mines whether its future matching sc can still succeed.A validate operation simply determines whether the noncur-rent pointer still points to the predecessor of the node stored in mynode by the ll operation.If so,a future sc can replace it with a new node,thereby ensuring its success.If our algorithm is used with a memory allocator that is not lock-free,then neither is our ll/sc implementation. While lock-free allocators exist[4,12],most standard alloca-tors are not lock-free.An alternative means for achieving a lock-free implementation is to use a lock-free freelist to man-age nodes.(We present a suitable freelist implementation in Section5.)The idea is to populate the freelist with enough nodes that one is always available for an sc operation to use.The number of nodes needed depends on the numbervoid enqueue(Value v){E1.Node∗nd=alloc(Node);E2.nd→v=v;nd→next=null;nd→exit=INIT EXIT;E3.while(true){E4.Node∗tail=ll(&Tail);E5.nd→pred=tail;E6.if(cas(&tail→next,null,nd)){E7.sc(&Tail,nd);E8.return;E9.}elseE10.sc(&Tail,tail→next);}}Value dequeue(){D1.while(true){D2.Node∗head=ll(&Head);D3.Node∗next=head→next;D4.if(next==null){D5.unlink(&Head);D6.return null;}D7.if(sc(&Head,next)){D8.Value v=next→v;D9.setToBeFreed(next);D10.return v;}}}Figure7:Queue operations.of threads that simultaneously access the implemented vari-able.If we cannot bound this number in advance,we can resort to the standard memory allocator to increase the size of the freelist upon thread creation,and remove nodes from the freelist and free them upon thread destruction.While this approach involves locking when creating or destroying a thread,we avoid locking during the lifetime of each thread.4.QUEUEIn this section,we describe a64-bit-clean lock-free FIFO queue implementation that is population-oblivious and con-sumes space proportional only to the number of items in the queue(and the number of threads currently accessing the queue).Our queue implementation is similar in struc-ture to that of Michael and Scott[13],but overcomes two important drawbacks.First,the implementation of[13]uses version numbers on its Head and Tail pointers,and is there-fore not64-bit-clean.Second,it cannot free nodes that have been dequeued;instead it stores them in a freelist for sub-sequent reuse,resulting in space consumption proportional to the historical maximum size of the queue.Figure7presents our queue code.Rather than modifying the Head and Tail pointers with cas and using version num-bers to avoid the ABA problem(as in[13]),we use ll and sc.If we ignore memory management issues for a moment, and assume that the ll and sc operations used are the stan-dard hardware-supported ones,then this implementation is essentially the one in[13].To facilitate the memory manage-ment required to achieve a64-bit-clean space-adaptive im-plementation,we use ll and sc operations similar to those presented in the previous section in place of the standard operations.。

Quasi-oppositional differential evolution

Quasi-Oppositional Differential EvolutionShahryar Rahnamayan1,Hamid R.Tizhoosh1,Magdy M.A.Salama2Faculty of Engineering,University of Waterloo,Waterloo,Ontario,N2L3G1,Canada 1Pattern Analysis and Machine Intelligence(PAMI)Research Group1,2Medical Instrument Analysis and Machine Intelligence(MIAMI)Research Group shahryar@pami.uwaterloo.ca,tizhoosh@uwaterloo.ca,m.salama@ece.uwaterloo.caAbstract—In this paper,an enhanced version of theOpposition-Based Differential Evolution(ODE)is pro-posed.ODE utilizes opposite numbers in the populationinitialization and generation jumping to accelerate Differ-ential Evolution(DE).Instead of opposite numbers,in thiswork,quasi opposite points are used.So,we call the newextension Quasi-Oppositional DE(QODE).The proposedmathematical proof shows that in a black-box optimizationproblem quasi-opposite points have a higher chance to becloser to the solution than opposite points.A test suite with 15benchmark functions has been employed to compare performance of DE,ODE,and QODE experimentally.Results confirm that QODE performs better than ODEand DE in overall.Details for the proposed approach andthe conducted experiments are provided.I.I NTRODUCTIONDifferential Evolution(DE)was proposed by Price and Storn in1995[16].It is an effective,robust,and sim-ple global optimization algorithm[8]which has only a few control parameters.According to frequently reported comprehensive studies[8],[22],DE outperforms many other optimization methods in terms of convergence speed and robustness over common benchmark func-tions and real-world problems.Generally speaking,all population-based optimization algorithms,no exception for DE,suffer from long computational times because of their evolutionary nature.This crucial drawback some-times limits their application to off-line problems with little or no real time constraints.The concept of opposition-based learning(OBL)was introduced by Tizhoosh[18]and has thus far been applied to accelerate reinforcement learning[15],[19], [20],backpropagation learning[21],and differential evolution[10]–[12],[14].The main idea behind OBL is the simultaneous consideration of an estimate and its corresponding opposite estimate(i.e.guess and opposite guess)in order to achieve a better approximation of the current candidate solution.Opposition-based deferential evolution(ODE)[9],[10],[14]uses opposite numbers during population initialization and also for generating new populations during the evolutionary process.In this paper,an OBL has been utilized to accelerate ODE.In fact,instead of opposite numbers,quasi oppo-site points are used to accelerate ODE.For this reason, we call the new method Quasi-Oppositional DE(QODE) which employs exactly the same schemes of ODE for population initialization and generation jumping.Purely random sampling or selection of solutions from a given population has the chance of visiting or even revisiting unproductive regions of the search space.A mathematical proof has been provided to show that,in general,opposite numbers are more likely to be closer to the optimal solution than purely random ones[13].In this paper,we prove the quasi-opposite points have higher chance to be closer to solution than opposite points.Our experimental results confirm that QODE outperforms DE and ODE.The organization of this paper is as follows:Differen-tial Evolution,the parent algorithm,is briefly reviewed in section II.In section III,the concept of opposition-based learning is explained.The proposed approach is presented in section IV.Experimental verifications are given in section V.Finally,the work is concluded in section VI.II.D IFFERENTIAL E VOLUTIONDifferential Evolution(DE)is a population-based and directed search method[6],[7].Like other evolution-ary algorithms,it starts with an initial population vec-tor,which is randomly generated when no preliminary knowledge about the solution space is available.Let us assume that X i,G(i=1,2,...,N p)are solution vectors in generation G(N p=population size).Succes-sive populations are generated by adding the weighted difference of two randomly selected vectors to a third randomly selected vector.For classical DE(DE/rand/1/bin),the mutation, crossover,and selection operators are straightforwardly defined as follows:Mutation-For each vector X i,G in generation G a mutant vector V i,G is defined byV i,G=X a,G+F(X b,G−X c,G),(1) 22291-4244-1340-0/07$25.00c 2007I EEEwhere i={1,2,...,N p}and a,b,and c are mutually different random integer indices selected from {1,2,...,N p}.Further,i,a,b,and c are different so that N p≥4is required.F∈[0,2]is a real constant which determines the amplification of the added differential variation of(X b,G−X c,G).Larger values for F result in higher diversity in the generated population and lower values cause faster convergence.Crossover-DE utilizes the crossover operation to generate new solutions by shuffling competing vectors and also to increase the diversity of the population.For the classical version of the DE(DE/rand/1/bin),the binary crossover(shown by‘bin’in the notation)is utilized.It defines the following trial vector:U i,G=(U1i,G,U2i,G,...,U Di,G),(2) where j=1,2,...,D(D=problem dimension)andU ji,G=V ji,G if rand j(0,1)≤C r∨j=k,X ji,G otherwise.(3)C r∈(0,1)is the predefined crossover rate constant, and rand j(0,1)is the j th evaluation of a uniform random number generator.k∈{1,2,...,D}is a random parameter index,chosen once for each i to make sure that at least one parameter is always selected from the mutated vector,V ji,G.Most popular values for C r are in the range of(0.4,1)[3].Selection-The approach that must decide which vector(U i,G or X i,G)should be a member of next(new) generation,G+1.For a maximization problem,the vector with the higherfitness value is chosen.There are other variants based on different mutation and crossover strategies[16].III.O PPOSITION-B ASED L EARNING Generally speaking,evolutionary optimization meth-ods start with some initial solutions(initial population) and try to improve them toward some optimal solu-tion(s).The process of searching terminates when some predefined criteria are satisfied.In the absence of a priori information about the solution,we usually start with some random guesses.The computation time,among others,is related to the distance of these initial guesses from the optimal solution.We can improve our chance of starting with a closer(fitter)solution by simultaneously checking the opposite guesses.By doing this,thefitter one(guess or opposite guess)can be chosen as an initial solution.In fact,according to probability theory,the likelihood that a guess is further from the solution than its opposite guess is50%.So,starting with thefitter of the two,guess or opposite guess,has the potential to accelerate convergence.The same approach can be applied not only to initial solutions but also continuously to each solution in the current population.Before concentrating on quasi-oppositional version of DE,we need to define the concept of opposite numbers [18]:Definition(Opposite Number)-Let x∈[a,b]be a real number.The opposite number˘x is defined by˘x=a+b−x.(4) Similarly,this definition can be extended to higher dimensions as follows[18]:Definition(Opposite Point)-Let P(x1,x2,...,x n) be a point in n-dimensional space,where x1,x2,...,x n∈R and x i∈[a i,b i]∀i∈{1,2,...,n}. The opposite point˘P(˘x1,˘x2,...,˘x n)is completely defined by its components˘x i=a i+b i−x i.(5) As we mentioned before,opposition-based differential evolution(ODE)employs opposite points in population initialization and generation jumping to accelerate the classical DE.In this paper,in order to enhance the ODE, instead of opposite points a quasi opposite points are utilized.Figure1andfigure2show the interval and region which are used to generate these points in one-dimensional and two-dimensional spaces,respectively.Fig.1.Illustration of x,its opposite˘x,and the interval[M,˘x] (showed by dotted arrow)which the quasi opposite point,˘x q,is generated in this interval.Fig.2.For a two-dimensional space,the point P,its opposite˘P, and the region(illustrated by shadow)which the quasi opposite point,˘P q,is generated in that area.Mathematically,we can prove that for a black-box optimization problem(which means solution can appear anywhere over the search space),that the quasi opposite point˘x q has a higher chance than opposite point˘x to be closer to the solution.This proof can be as follows: Theorem-Given a guess x,its opposite˘x and quasi-opposite˘x q,and given the distance from the solution d(.)and probability function P r(.),we haveP r[d(˘x q)<d(˘x)]>1/2(6) Proof-Assume,the solution is in one of these intervals:[a,x],[x,M],[M,˘x],[˘x,b]22302007IEEE Co ngr e ss o n Evo luti o nar y Co mputati o n(CEC2007)([a,x ]∪[x,M ]∪[M,˘x ]∪[˘x ,b ]=[a,b ]).Weinvestigate all cases:•[a,x ],[˘x ,b ]-According to the definition of opposite point,intervals [a,x ]and [˘x ,b ]have the same length,so the probability of that the solution bein interval [a,x ]or [˘x ,b ]is equal (x −a b −a =b −˘x b −a ).Now,if the solution is in interval [a,x ],definitely,it is closer to ˘x q and in the same manner if it is in interval [˘x ,b ]it would be closer to ˘x .So,untilnow,˘x qand ˘xhave the equal chance to be closer to the solution.•[M,˘x ]-For this case,according to probabilitytheory,˘x q and ˘xhave the equal chance to be closer to the solution.•[x,M ]-For this case,obviously,˘x q is closer to the solution than ˘x .Now,we can conclude that,in overall,˘x q has a higher chance to be closer to the solution than ˘x ,because for the first two cases they had equal chance and just for last case ([x,M ])˘x q has a higher chance to be closer to the solution.This proof is for a one-dimensional space but the conclusion is the same for the higher dimensions:P rd (˘P q )<d (˘P ) >1/2(7)Because according to the definition of Euclideandistance between two points Y (y 1,y 2,...,y D )and Z (z 1,z 2,...,z D )in a D-dimensional spaced (Y,Z )= Y,Z = Di =1(y i −z i )2,(8)If in each dimension ˘x q has a higher chance to be closer to the solution than ˘x ,consequently,the point ˘Pq ,in a D-dimensional space,will have a higher chance to be closer to solution than P .Now let us define an optimization process which uses a quasi-oppositional scheme.Quasi-Oppositional OptimizationLet P (x 1,x 2,...,x D )be a point in an D-dimensionalspace (i.e.a candidate solution)and ˘P q (˘x q 1,˘x q 2,...,˘x q D )be a quasi opposite point (see figure 2).Assume f (·)is a fitness function which is used to measure the candidate’sfitness.Now,if f (˘Pq )≥f (P ),then point P can be replaced with ˘Pq ;otherwise we continue with P .Hence,we continue with the fitter one.IV.P ROPOSED A LGORITHMSimilar to all population-based optimization algo-rithms,two main steps are distinguishable for DE,namely population initialization and producing newgenerations by evolutionary operations such as selec-tion,crossover,and mutation.Similar to ODE,we will enhance these two steps using the quasi-oppositional scheme.The classical DE is chosen as a parent algorithm and the proposed scheme is embedded in DE to acceler-ate the convergence speed.Corresponding pseudo-code for the proposed approach (QODE)is given in Table I.Newly added /extended code segments will be explained in the following subsections.A.Quasi-Oppositional Population InitializationAccording to our review of optimization literature,random number generation,in absence of a priori knowl-edge,is the only choice to create an initial population.By utilizing quasi-oppositional learning we can obtain fitter starting candidate solutions even when there is no a priori knowledge about the solution(s).Steps 1-12from Table I present the implementation of quasi-oppositional initialization for QODE.Following steps show that procedure:1)Initialize the population P 0(N P )randomly,2)Calculate quasi-opposite population (QOP 0),steps 5-10from Table I,3)Select the N p fittest individuals from {P 0∪QOP 0}as initial population.B.Quasi-Oppositional Generation JumpingBy applying a similar approach to the current popu-lation,the evolutionary process can be forced to jump to a new solution candidate,which ideally is fitter than the current one.Based on a jumping rate J r (i.e.jumping probability),after generating new populations by selection,crossover,and mutation,the quasi-opposite population is calculated and the N p fittest individuals are selected from the union of the current population and the quasi-opposite population.As a difference to quasi-oppositional initialization,it should be noted here that in order to calculate the quasi-opposite population for generation jumping,the opposite of each variable and middle point are calculated dynamically.That is,the maximum and minimum values of each variablein the current population ([MIN p j ,MAX pj ])are used to calculate middle-to-opposite points instead of using variables’predefined interval boundaries ([a j ,b j ]).By staying within variables’interval static boundaries,we would jump outside of the already shrunken search space and the knowledge of the current reduced space (converged population)would be lost.Hence,we calcu-late new points by using variables’current interval in thepopulation ([MIN p j ,MAX pj ])which is,as the search does progress,increasingly smaller than the corresponding initial range [a j ,b j ].Steps 33-46from Table I show the implementation of quasi-oppositional generation jumping for QODE.2007IEEE Co ngr e ss o n Evo luti o nar y Co mputati o n (CEC 2007)2231TABLE IP SEUDO-CODE FOR Q UASI-O PPOSITIONAL D IFFERENTIAL E VOLUTION(QODE).P0:I NITIAL POPULATION,OP0:O PPOSITE OF INITIAL POPULATION,N p:P OPULATION SIZE,P:C URRENT POPULATION,OP:O PPOSITE OF CURRENT POPULATION,V:N OISE VECTOR,U:T RIAL VECTOR,D:P ROBLEM DIMENSION,[a j,b j]:R ANGE OF THE j-TH VARIABLE,BFV:B EST FITNESS VALUE SO FAR,VTR:V ALUE TO REACH,NFC:N UMBER OF FUNCTION CALLS,MAX NFC:M AXIMUM NUMBER OF FUNCTION CALLS,F:M UTATION CONSTANT,rand(0,1): U NIFORMLY GENERATED RANDOM NUMBER,C r:C ROSSOVER RATE,f(·):O BJECTIVE FUNCTION,P :P OPULATION OF NEXT GENERATION,J r:J UMPING RATE,MIN p j:M INIMUM VALUE OF THE j-TH VARIABLE IN THE CURRENT POPULATION,MAX p j:M AXIMUM VALUE OF THE j-TH VARIABLE IN THE CURRENT POPULATION,M i,j:M IDDLE P OINT.S TEPS1-12AND33-46ARE IMPLEMENTATIONS OF QUASI-OPPOSITIONAL POPULATION INITIALIZATION AND GENERATION JUMPING,RESPECTIVELY.Quasi-Oppositional Differential Evolution(QODE)/*Quasi-Oppositional Population Initialization*/1.Generate uniformly distributed random population P0;2.for(i=0;i<N p;i++)3.for(j=0;j<D;j++)4.{5.OP0i,j=a j+b j−P0i,j;6.M i,j=(a j+b j)/2;7.if(P0i,j<M i,j)8.QOP0i,j=M i,j+(OP0i,j−M i,j)×rand(0,1);9.else10.QOP0i,j=OP0i,j+(M i,j−OP0i,j)×rand(0,1);11.}12.Select N pfittest individuals from set the{P0,QOP0}as initial population P0;/*End of Quasi-Oppositional Population Initialization*/13.while(BFV>VTR and NFC<MAX NFC)14.{15.for(i=0;i<N p;i++)16.{17.Select three parents P i1,P i2,and P i3randomly from current population where i=i1=i2=i3;18.V i=P i1+F×(P i2−P i3);19.for(j=0;j<D;j++)20.{21.if(rand(0,1)<C r∨j=k)22.U i,j=V i,j;23.else24.U i,j=P i,j;25.}26.Evaluate U i;27.if(f(U i)≤f(P i))28.P i=U i;29.else30.P i=P i;31.}32.P=P ;/*Quasi-Oppositional Generation Jumping*/33.if(rand(0,1)<J r)34.{35.for(i=0;i<N p;i++)36.for(j=0;j<D;j++)37.{38.OP i,j=MIN p j+MAX p j−P i,j;39.M i,j=(MIN p j+MAX p j)/2;40.if(P i,j<M i,j)41.QOP i,j=M i,j+(OP i,j−M i,j)×rand(0,1);42.else43.QOP i,j=OP i,j+(M i,j−OP i,j)×rand(0,1);44.}45.Select N pfittest individuals from set the{P,QOP}as current population P;46.}/*End of Quasi-Oppositional Generation Jumping*/47.}22322007IEEE Co ngr e ss o n Evo luti o nar y Co mputati o n(CEC2007)V.E XPERIMENTAL V ERIFICATIONIn this section we describe the benchmark functions,comparison strategies,algorithm settings,and present the results.A.Benchmark FunctionsA set of 15benchmark functions (7unimodal and 8multimodal functions)has been used for performance verification of the proposed approach.Furthermore,test functions with two different dimensions (D and 2∗D )have been employed in the conducted experiments.By this way,the classical differential evolution (DE),opposition-based DE (ODE),and quasi-oppositional DE (QODE)are compared on 30minimization problems.The definition of the benchmark functions and their global optimum(s)are listed in Appendix A.The 13functions (out of 15)have an optimum in the center of searching space,to make it asymmetric the search space for all of these functions are shifted a 2as follows:If O.P.B.:−a ≤x i ≤a and f min =f (0,...,0)=0then S.P.B.:−a +a 2≤x i ≤a +a2,where O.P.B.and S.P.B.stand for original parameter bounds and shifted parameter bounds ,parison Strategies and MetricsIn this study,three metrics,namely,number of func-tion calls (NFC),success rate (SR),and success per-formance (SP)[17]have been utilized to compare the algorithms.We compare the convergence speed by mea-suring the number of function calls which is the most commonly used metric in literature [10]–[12],[14],[17].A smaller NFC means higher convergence speed.The termination criterion is to find a value smaller than the value-to-reach (VTR)before reaching the maximum number of function calls MAX NFC .In order to minimize the effect of the stochastic nature of the algorithms on the metric,the reported number of function calls for each function is the average over 50trials.The number of times,for which the algorithm suc-ceeds to reach the VTR for each test function is mea-sured as the success rate SR:SR =number of times reached VTRtotal number of trials.(9)The average success rate (SR ave )over n test functions are calculated as follows:SR ave=1n ni =1SR i .(10)Both of NFC and SR are important measures in an op-timization process.So,two individual objectives should be considered simultaneously to compare competitors.In order to combine these two metrics,a new measure,called success performance (SP),has been introduced as follows [17]:SP =mean (NFC for successful runs)SR.(11)By this definition,the two following algorithms have equal performances (SP=100):Algorithm A:mean (NFC for successful runs)=50and SR=0.5,Algorithm B:mean (NFC for successful runs)=100and SR=1.SP is our main measure to judge which algorithm performs better than others.C.Setting Control ParametersParameter settings for all conducted experiments are as follows:•Population size,N p =100[2],[4],[23]•Differential amplification factor,F =0.5[1],[2],[5],[16],[22]•Crossover probability constant,C r =0.9[1],[2],[5],[16],[22]•Jumping rate constant for ODE,J r ODE =0.3[10]–[12],[14]•Jumping rate constant for QODE,J r QODE =0.05•Maximum number of function calls,MAX NFC =106•Value to reach,VTR =10−8[17]The jumping rate for QODE is set to a smaller value(J r QODE =16J r ODE )because our trials showed that the higher jumping rates can reduce diversity of the population very fast and cause a premature convergence.This was predictable for QODE because instead of opposite point a random point between middle point and the opposite point is generated and so variable’s search interval is prone to be shrunk very fast.A com-plementary study is required to determine an optimal value /interval for QODE’s jumping rate.D.ResultsResults of applying DE,ODE,and QODE to solve 30test problems (15test problems with two different dimensions)are given in Table II.The best NFC and the success performance for each case are highlighted in boldface.As seen,QODE outperforms DE and ODE on 22functions,ODE on 6functions,and DE just on one function.DE performs marginally better than ODE and QODE in terms of average success rate (0.90,0.88,and 0.86,respectively).ODE surpasses DE on 26functions.As we mentioned before,the success performance is a measure which considers the number of function2007IEEE Co ngr e ss o n Evo luti o nar y Co mputati o n (CEC 2007)2233calls and the success rate simultaneously and so it can be utilized for a reasonable comparison of optimization algorithms.VI.C ONCLUSIONIn this paper,the quasi-oppositional DE(QODE),an enhanced version of the opposition-based differential evolution(ODE),is proposed.Both algorithms(ODE and QODE)use the same schemes for population initial-ization and generation jumping.But,QODE uses quasi-opposite points instead of opposite points.The presented mathematical proof confirms that this point has a higher chance than opposite point to be closer to the solution. Experimental results,conducted on30test problems, clearly show that QODE outperforms ODE and DE. Number of function calls,success rate,and success performance are three metrics which were employed to compare DE,ODE,and QODE in this study. According to our studies on the opposition-based learning,thisfield presents the promising potentials but still requires many deep theoretical and empirical investigations.Control parameters study(jumping rate in specific),adaptive setting of the jumping rate,and investigating of QODE on a more comprehensive test set are our directions for the future study.R EFERENCES[1]M.Ali and A.T¨o rn.Population set-based global optimization al-gorithms:Some modifications and numerical studies.Journal of Computers and Operations Research,31(10):1703–1725,2004.[2]J.Brest,S.Greiner,B.Boškovi´c,M.Mernik,and V.Žumer.Self-adapting control parameters in differential evolution:A comparative study on numerical benchmark problems.Journal of I EEE Transactions on Ev olutionar y Computation,10(6):646–657,2006.[3]S.Das,A.Konar,and U.Chakraborty.Improved differentialevolution algorithms for handling noisy optimization problems.In Proceedings of I EEE Congress on Ev olutionar y Computation Conference,pages1691–1698,Napier University,Edinburgh, UK,September2005.[4] C.Y.Lee and X.Yao.Evolutionary programming usingmutations based on the lévy probability distribution.Journal of I EEE Transactions on Ev olutionar y Computation,8(1):1–13, 2004.[5]J.Liu and mpinen.A fuzzy adaptive differential evolutionalgorithm.Journal of Soft Computing-A Fusion of Foundations, Methodologies and Applications,9(6):448–462,2005.[6]G.C.Onwubolu and B.Babu.New Optimization Techniques inE ngineering.Springer,Berlin,New York,2004.[7]K.Price.An Introduction to Differential Ev olution.McGraw-Hill,London(UK),1999.ISBN:007-709506-5.[8]K.Price,R.Storn,and mpinen.Differential Ev olution:A Practical Approach to Global Optimization.Springer-Verlag,Berlin/Heidelberg/Germany,1st edition edition,2005.ISBN: 3540209506.[9]S.Rahnamayan.Opposition-Based Differential Ev olution.Phdthesis,Deptartement of Systems Design Engineering,University of Waterloo,Waterloo,Canada,April2007.[10]S.Rahnamayan,H.Tizhoosh,and M.Salama.Opposition-baseddifferential evolution algorithms.In Proceedings of the2006I EEE World Congress on Computational Intelligence(C E C-2006),pages2010–2017,Vancouver,BC,Canada,July2006.[11]S.Rahnamayan,H.Tizhoosh,and M.Salama.Opposition-baseddifferential evolution for optimization of noisy problems.In Proceedings of the2006I EEE World Congress on Computational Intelligence(C E C-2006),pages1865–1872,Vancouver,BC, Canada,July2006.[12]S.Rahnamayan,H.Tizhoosh,and M.Salama.Opposition-based differential evolution with variable jumping rate.InI EEE S y mposium on Foundations of Computational Intelligence,Honolulu,Hawaii,USA,April2007.[13]S.Rahnamayan,H.Tizhoosh,and M.Salama.Opposition versusrandomness in soft computing techniques.submitted to theE lse v ier Journal on Applied Soft Computing,Aug.2006.[14]S.Rahnamayan,H.Tizhoosh,and M.Salama.Opposition-based differential evolution.accepted at the Journal of I EEE Transactions on Ev olutionar y Computation,Dec.2006. [15]M.Shokri,H.R.Tizhoosh,and M.Kamel.Opposition-basedq(λ)algorithm.In Proceedings of the2006I EEE World Congress on Computational Intelligence(IJCNN-2006),pages649–653, Vancouver,BC,Canada,July2006.[16]R.Storn and K.Price.Differential evolution:A simple andefficient heuristic for global optimization over continuous spaces.Journal of Global Optimization,11:341–359,1997.[17]P.N.Suganthan,N.Hansen,J.J.Liang,K.Deb,Y.P.Chen,A.Auger,and S.Tiwari.Problem definitions and evaluationcriteria for the cec2005special session on real-parameter optimization.Technical Report2005005,Kanpur Genetic Al-gorithms Laboratory,IIT Kanpur,Nanyang Technological Uni-versity,Singapore And KanGAL,May2005.[18]H.Tizhoosh.Opposition-based learning:A new scheme formachine intelligence.In Proceedings of the International Con-ference on Computational Intelligence for Modelling Control and Automation(CIMCA-2005),pages695–701,Vienna,Austria, 2005.[19]H.Tizhoosh.Reinforcement learning based on actions andopposite actions.In Proceedings of the International Conference on Artificial Intelligence and Machine Learning(AIML-2005), Cairo,Egypt,2005.[20]H.Tizhoosh.Opposition-based reinforcement learning.Journalof Ad v anced Computational Intelligence and Intelligent Infor-matics,10(3),2006.[21]M.Ventresca and H.Tizhoosh.Improving the convergence ofbackpropagation by opposite transfer functions.In Proceedings of the2006I EEE World Congress on Computational Intelligence (IJCNN-2006),pages9527–9534,Vancouver,BC,Canada,July 2006.[22]J.Vesterstroem and R.Thomsen.A comparative study of differ-ential evolution,particle swarm optimization,and evolutionary algorithms on numerical benchmark problems.In Proceedings of the Congress on Ev olutionar y Computation(C E C-2004),I EEE Publications,volume2,pages1980–1987,San Diego,California, USA,July2004.[23]X.Yao,Y.Liu,and G.Lin.Evolutionary programming madefaster.Journal of I EEE Transactions on Ev olutionar y Computa-tion,3(2):82,1999.A PPENDIX A.L IST OF BENCHMARK FUNCTIONS O.P.B.and S.P.B.stand for the original parameter bounds and the shifted parameter bounds,respecti v el y. All the conducted experiments are based on S.P.B.•1st De Jongf1(X)=ni=1x i2,O.P.B.−5.12≤x i≤5.12,S.P.B.−2.56≤x i≤7.68,min(f1)=f1(0,...,0)=0.22342007IEEE Co ngr e ss o n Evo luti o nar y Co mputati o n(CEC2007)TABLE IIC OMPARISON OF DE,ODE,AND QODE.D:D IMENSION,NFC:N UMBER OF FUNCTION CALLS(AVERAGE OVER50TRIALS),SR:S UCCESS RATE,SP:S UCCESS PERFORMANCE.T HE LAST ROW OF THE TABLE PRESENTS THE AVERAGE SUCCESS RATES.T HE BEST NFC AND THE SUCCESS PERFORMANCE FOR EACH CASE ARE HIGHLIGHTED IN boldface.DE,ODE,AND QODE ARE UNABLE TO SOLVE f10(D=60).D E OD E QOD EF D NFC SR SP NFC SR SP NFC SR SPf130860721860725084415084442896142896601548641154864101832110183294016194016 f23095080195080569441569444707214707260176344117634411775611177561059921105992 f32017458011745801773001177300116192111619240816092181609283466818346685396081539608 f4103237700.96337260752780.92818231811001181100208113700.08101421254213000.1626331256152800.163845500 f5301114400.96116083747170.92812141005400.801256756019396011939601283400.681887351152800.68169529 f6301876011876010152110152945219452603312813312811452111452146670.8417461 f73016837211683721002801100280824481824486029450012945002020100.962104272218500.72308125 f83010146011014607040817040850576150576601802600.842150001217500.60202900983000.40245800 f9101913400.762520002133300.563809002476400.48515900202883000.358240002539100.554617001933300.68284300 f103038519213851923691041369104239832123983260−0−−0−−0−f113018340811834081675801167580108852110885260318112131811227471612747161831321183132 f123040240140240264001264002107612107660736161736166478016478064205164205 f13303869201386920361884136188429144812914486043251614325164257000.964434382950841295084 f141019324119324161121161121397211397220457881457883172013172023776123776 f15103726013726026108126108189441189442017687211768725788815788840312140312SR ave0.900.880.86•Axis Parallel H y per-E llipsoidf2(X)=ni=1ix i2,O.P.B.−5.12≤x i≤5.12,S.P.B.−2.56≤x i≤7.68,min(f2)=f2(0,...,0)=0.•Schwefel’s Problem1.2f3(X)=ni=1(ij=1x j)2,O.P.B.−65≤x i≤65,S.P.B.−32.5≤x i≤97.5,min(f3)=f3(0,...,0)=0.•Rastrigin’s Functionf4(X)=10n+ni=1(x2i−10cos(2πx i)),O.P.B.−5.12≤x i≤5.12, S.P.B.−2.56≤x i≤7.68, min(f4)=f4(0,...,0)=0.•Griewangk’s Functionf5(X)=ni=1x2i4000−ni=1cos(x i√i)+1,O.P.B.−600≤x i≤600,S.P.B.−300≤x i≤900,min(f5)=f5(0,...,0)=0.•Sum of Different Powerf6(X)=ni=1|x i|(i+1),O.P.B.−1≤x i≤1,S.P.B.−0.5≤x i≤1.5,min(f6)=f6(0,...,0)=0.•Ackle y’s Problemf7(X)=−20exp(−0.2ni=1x2i)−exp(ni=1cos(2πx i))+ 20+e,O.P.B.−32≤x i≤32,S.P.B.−16≤x i≤48,min(f7)=f7(0,...,0)=0.2007IEEE Co ngr e ss o n Evo luti o nar y Co mputati o n(CEC2007)2235。

集值优化中扰动映射的二阶S导数的灵敏度分析

2020年12月Dec., 2020运筹学学报O p e r a t i o n s R e s e a r c h T r a n s a c t i o n s第24卷第4期V o l.24N o.4D O I:10.15960/j.c n k i.i s s n.l007-6093.2020.04.007集值优化中扰动映射的二阶S导数的灵敏度分析*汤卫杨赞3摘要引进一种新的二阶切导数,称为二阶S导数,并讨论它的性质以及它与二阶切导数的关系。

借助二阶S导数,建立集值映射切导数的极小值与扰动映射切导数之间的关系。

关键词二阶S导数,集值映射,扰动映射中图分类号0221,02242010数学分类号90C29, 90C30S e n sitiv ity for th e secon d-ord er ^-d eriv a tiv e o f th e p ertu rb a tio n m ap in set-v a lu ed op tim ization*T A N G W ei*1-23-1 Y A N G Yun3Abstract I n this p a p e r, a n e w k i n d o f s e c o n d-o r d e r c o n t i n g e n t derivative is intro­d u ce d,t e r m e d s e c o n d-o r d e r5-derivative. S o m e p r o p e r t i e s of s e c o n d-o r d e r 5-d e r i v a t i v ea n d t h e relationship t o s e c o n d-o r d e r c o n t i n g e n t derivative a r e discussed. T h e n, w i t h t h eh e l p o f s e c o n d-o r d e r 5-derivative, relationships a r e esta b l i s h e d b e t w e e n t h e m i n i m u m ofc o n t i n g e n td erivative of set-v a l u e d m a p s a n d c o n t i ng e n t derivative o f p e r t u r b a t i o n m a p s.Keywords s e c o n d-o r d e r 5-derivative, s e t-v a l u e d m a p, p e r t u r b a t i o n m a pChinese Library Classification 0221, 02242010 M athem atics Subject Classification 90C29, 90C300引言在集值优化理论中,灵敏度分析是一种对含参变量优化问题中扰动映射切导数的研 宄。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

LDTA’04Preliminary VersionParameterized LR ParsingPeter Thiemann and Matthias Neubauer1,2Institut f¨u r InformatikUniversit¨a t FreiburgGeorges-K¨o hler-Allee079D-79110Freiburg,GermanyAbstractCommon LR parser generators lack abstraction facilities for defining recurring pat-terns of productions.Although there are generators capable of supporting regular expressions on the right hand side of productions,no generator supports user defined patterns in grammars.Parameterized LR parsing extends standard LR parsing technology by admitting grammars with parameterized non-terminal symbols.A generator can implement such a grammar in two ways,either by expansion or directly.We develop the theory required for the direct implementation and show that it leads to significantly smaller parse tables and that it has fewer parsing conflicts than the expanded grammar. Attribute evaluation for a parameterized non-terminal is possible in the same way as before,if the semantic functions related to the non-terminal are polymorphic with respect to the parameter.We have implemented parameterized LR parsing in the context of Essence,a partial-evaluation based LR parser generator for Scheme.1IntroductionLR parsing[11]is a powerful tool in the toolbox of the language designer. It provides a parsing algorithm that works in linear time for a wide range of context-free grammars.The theory of LR parsing has been explored in numerous works and it has become a standard part of lectures and textbooks on compiler construction[1].It also forms the foundation of a whole range of parser generation tools starting with yacc/bison[10,5],the ideas of which have been adapted to virtually any programming language around.While there has been some evolution of the tools with respect to modular-ization of parsing actions and integration of the specifications of parsing and 1Email:thiemann@informatik.uni-freiburg.de2Email:neubauer@informatik.uni-freiburg.descanning,the actual raw matter,the grammar,remains in its original form in the parser specification.Since large grammars may well run into several hun-dred productions,grammar maintenance can become a tedious task.Hence, it is surprising that none of the parser generators has a facility for introducing abstractions over grammar rules.The main attempt to introduce some abbreviation mechanism into LR grammars is the consideration of regular right-hand sides for rules[3].How-ever,only a few LR parser generators(e.g.,[8])support regular right hand sides or extended BNF directly.Consequently,typical grammars for LR parser generators are full of rule groups that implement common grammatical pat-terns.Here are some examples with the number of uses of that pattern from a randomly picked grammar.•lists with separator(seven times)DelimTypeSchemes:/*empty*/|NEDelimTypeSchemes; NEDelimTypeSchemes:TypeScheme|NEDelimTypeSchemes’,’TypeScheme;•plain lists(five times plus two non-empty lists)TypeVars:/*empty*/|NETypeVars;NETypeVars:TypeVar|NETypeVars TypeVar;•optional items(two times)Imports:/*empty*/|Imports import typename;Often,even the semantic actions coincide or can be made to coincide easily.Our proposal derives almost directly from these observations.Instead of relying on afixed set of(regular)operators for use in the right-hand side of grammar rules,we make available an arbitrary,user-definable set of operators in the form of parameterizable nonterminal symbols.These nonterminals are used like functions.They can be invoked with actual parameters in the right-hand side of a production.Some care must be taken to restrict the actual parameters suitably,for example,to only one nonterminal or one formal pa-rameter.Without restriction to the actual parameters,we would obtain the notion of a macro grammar which is strictly more powerful than a context-free grammar[4].With our proposed extension,a grammar writer can write parameterized productions corresponding to the patterns exhibited above once and for all. Sets of parameterized nonterminals might be collected in modules and reused between grammars.The following example shows parameterized rules for the grammatical pat-terns identified above.SepList(Sep,Item):/*empty*/|NESepList(Sep,Item);NESepList(Sep,Item):Item|NESepList(Sep,Item)Sep Item;List(Item):/*empty*/|NEList(Item);NEList(Item):Item|NEList(Item)Item;Option(Item):/*empty*/|Item;For the examples above it also makes sense to define generic semantic actions.The only requirement is that these actions are polymorphic with respect to the semantic values of the parameters.Hence,the SepList(Sep, Item)and the List(Item)might both return a value of type List Item and the Option(Item)might return a value of type Maybe Item.Type-specific semantic actions should take place when returning from parameterized nonterminal instantiated with actual nonterminals.One way of implementing parameterized LR parsing is by separately spe-cializing parameterized nonterminals with respect to all the nonterminals ac-tually instantiated as parameters separately.This specialization terminates trivially because of our restriction on actual parameters.However,it turns out that developing the theory directly for parameterized grammars yields smaller parse tables(since the parameterized parts can be shared)and some-times avoids parsing conflicts.We have extended the LR(k)parser generator Essence[17]to generate parameterized LR(k)parsers.Initial experiments with the implementation are encouraging.OverviewBefore developing the theory of parameterized LR parsing,we make an excur-sion into formal language theory to introduce the reader to macro grammars and macro languages in Section2.After defining a suitably restricted notion of macro grammar,Section3introduces the basic definitions for parameterized LR parsing.Section4defines the parsing algorithm,starting with a non-deterministic specification and then defining the notion of conflict to obtain deterministic parsers.Section5is devoted to attribute evaluation.It defines a type system that assigns polymorphic types to parameterized nonterminals. Section6describes our implementation of parameterized LR parsing in the context of Essence,a parser generator for Scheme.Finally,Section7considers related work and Section8concludes and sketches some future work.2Macro GrammarsTo define macro grammars properly,we need some standard definitions from universal algebra.A signature is a pairΓ=(N,a)of afinite set N and an arity function a:N→N,the set of non-negative integers.The set TΓ(X)of Γ-terms with variables X(a set disjoint from N)is defined inductively by •X⊆TΓ(X)•(∀n∈N,t1...t n∈TΓ(X),A∈N)a(A)=n⇒A(t1,...,t n)∈TΓ(X).Definition2.1A macro grammar is a quadruple(Γ,Σ,P,S)whereΓ= (N,a)is a signature with N the nonterminal symbols,Σis afinite set of terminal symbols,P⊆N×TΓ (Σ∪N)is afinite set of macro productions, and S∈N with a(S)=0is the start symbol.The signatureΓ extendsΓby a binary operator·(concatenation)and a constantε(empty string).The productions are subject to the following restriction.If A→w∈P with a(A)=n,then w∈TΓ (Σ∪{0,...,n−1}).A macro grammar generates words over the set of terminal symbols using the following derivation relation⇒on TΓ (Σ).•If A→w∈P,a(A)=n,t1...t n∈TΓ (Σ),then A(t1,...,t n)⇒w[0→t1,...,n−1→t n],and•if f∈Γ ,a(f)=n,t1...t n∈TΓ (Σ),t i⇒t i,then f(t1,...,t i,...,t n)⇒f(t1,...,t I,...,t n).That is,the relation comprises all pairs of terms and it is closed under compat-ibility.As usual,∗⇒denotes the reflexive transitive closure of the derivation relation.A term w is in the language generated by the grammar if S∗⇒w and w∈T·,ε(Σ),which can be considered as an element ofΣ∗in the obvious way.Usually,the derivation relation is restricted to either substitute nontermi-nals inside-out(IO)or outside-in(OI).IO reduction A(t1,...,t n)⇒IO w[0→t1,...,n−1→t n]only if t1,...,t n∈T·,ε(Σ)(they do not contain nonterminals)and the relation is closed under compatibility as before.OI reduction the reduction rule for⇒OI is the same as for⇒,but compat-ibility is restricted to f∈{·,ε}(reduction does not proceed into argument positions).The respective languages are called IO-and OI-macro languages.They have been investigated in detail[7]and we recall some of their properties below.3 3The definition we are giving above is not the one that has been used to obtain the cited results.The original definition considers strings as trees build from monadic operators (the characters)so that standard nonterminals in a context-free grammar are also monadic operators serving as placeholders for trees.In a macro grammar,nonterminals receive additional parameters that range over monadic operators.Adding further parameter sets(i)In general,the language generated from a grammar under IO reductionis different from the language generated under OI reduction.(One corre-sponds to call-by-value,the other to call-by-name.)(ii)The classes of IO-and OI-macro languages are incomparable.(iii)The IO-and OI-macro languages are a strict hierarchy of languages be-tween context-free languages and context-sensitive languages[4].The macro grammars that we have introduced here only correspond to the first level of the hierarchy mentioned above.However,taken in their full generality,they can describe languages that are not context-free.For example, the following macro grammar generates the set{a n b n c n|n∈N}:S→F(ε,ε,ε)F(A,B,C)→ABCF(A,B,C)→F(aA,bB,cC)Here,we have taken the liberty of naming the parameters of F instead of using the numbering scheme from the definition.Since we are interested in making abstractions to help define context-free languages only,we need to restrict the general definition.Definition2.2A restricted macro grammar is a macro grammar(Γ,Σ,P,S) where each production has the form A→t1···t m(for m∈N)such that,for each1≤i≤m,either t i∈Σor t i=B(s0,...,s l−1)where l=a(B)and,for each0≤j<l,either s j∈N with a(s j)=0,a nullary nonterminal symbol, or s j∈{0,...,a(A)−1},a parameter symbol.Each restricted macro grammar determines a context-free grammar by spe-cialization of the nonterminals with respect to their parameters.The resulting grammar is determined by(N ,Σ,P ,(S,ε))whereN ={(A,A0...A n−1)|A,A0,...,A n−1∈N,a(A)=n,a(A i)=0}⊆N×N∗P ={(A,A0...A n−1)→|t1|A0...A n−1···|t m|A0...A n−1|A→t1···t m∈P}where(for a∈Σ,j∈N)|a|A0...A n−1=a|B(s0,...,s l−1)|A0...A n−1=(B,||s0||A0...A n−1...||s l−1||A0...A n−1)|j|A0...A n−1=(A j,ε)||C||A0...A n−1=C||j||A0...A n−1=A j leads to higher levels in the mentioned hierarchy.The following lemma makes the connection precise.The language of the specialized grammar corresponds to the language of the restricted macro gram-mar under OI-reduction.Lemma2.3Let M=(Γ,Σ,P,S)be a restricted macro grammar and G= (N ,Σ,P ,S)the corresponding context-free grammar as constructed above.S∗⇒M,OI w iff(S,ε)∗⇒G w.Proof.We show that each derivation step in M corresponds to a derivation step in G.Since OI reduction restricts compatibility to the concatenation operator, all terms derivable from S in M can be written in the form s1···s m where, for each i,either s i∈Σor s i=A i(A i0,...,A i),for some nullary non-a(A i)−1terminals A i j.(This can be proven by induction on the number of derivation steps for S∗⇒M,OI s1···s m.)Hence,the translation function|···|B...from the construction above is applicable to all derivable terms where the subscript is empty since no pa-rameters occur in derivable terms.It remains to see that if S∗⇒M,OIαand α⇒M,OIα ,then|α|⇒G|α |.But this is immediate from the construction of the production set P .2 Hence,restricted macro grammars with OI reduction define exactly context-free languages.The restriction that actual parameters are either single nonter-minals or formal parameters is less severe than it may appear.Alternatively, the actual parameters may be restricted to either a single formal parameter or an arbitrary word over terminals and(nullary)nonterminals.Such a gram-mar can be transformed to restricted form as defined above by introducing new nullary nonterminals for each word that appears as an actual parameter. However,definition2.2is easier to work with formally.Example2.4A restricted macro grammar for a fragment of the grammar of JavaScript[6]expressions serves as running example.The fragment encom-passes constants,c,array literals enclosed in[and],as well as object literals enclosed in{and}.Array and object literals both contain comma-separated lists modeled with the parameterized nonterminals L and N.Object literals consist of key-value assignments as described by nonterminal A.Terminal symbols are indicated by typewriter font.S→E E→c E→{L(C,A)}E→[L(C,E)]C→,A→c:EL→εL→N(0,1)N→1N→N(0,1)01 Remark2.5The construction from Lemma2.3does not rely on the fact that parameters are nullary nonterminals.It works for(a suitable notion of) restricted higher-order OI-macro grammars,as well.3Parameterized LR ParsingStarting from a restricted macro grammar M,we develop the core theory of LR parsing,starting with LR items.For the sake of a name,they are called parameterized LR items,or short PLR items.All definitions are given relative to the arbitrary,butfixed,grammar M=(Γ,Σ,P,S)withΓ=(N,a).Let further k∈N be the lookahead,i.e.,the number of characters used to decide on a parsing action.We assume familiarity with the standard notions of LR parsing theory.Definition3.1A PLR(k)item is a triple of a production A→t1···t m,an integer i with0≤i≤m,and a string v∈Σ∗with length|v|≤k.It is written [A→t1···t i•···t m,v],if i>0,or[A→•t1···t m,v],if i=0.The standard theory defines a nondeterministicfinite automaton withεtransitions with the set of LR items as states.In the presence of parameters, the automaton construction needs to be generalized to a transition graph with an additional kind of arcs in comparison to afinite automaton.The construction of this graph requires—as in the standard case—the computation of k-prefixes of right-hand sides of rules.However,since right-hand sides can now contain parameters,this computation must take place relative to a parameter instance.Definition3.2A parameter instance is a tuple of nullary nonterminals C= (C0,...,C m−1).A parameter instantiation(for C)is a tuple s=(s0,...,s l−1)of nullary nonterminals or parameter references(i.e.,integers in the range0...m−1).The application s(C)of parameter instantiation s to parameter instance C yields a new parameter instance s(C)=D=(D0,...,D l−1)where D i=s i, if s i is a nullary nonterminal,and D i=C j if s i=j,a parameter reference.The well-known construction of afirst-k set for the right-hand side of a production needs to be parameterized with respect to an instance.Definition3.3The set of k-prefixes of an right-hand side term with respect to instance C is defined(with respect to M)byfirst C k(ε)={ε}first C k(α·β)={prefix k(vw)|v∈first C k(α),w∈first C k(β)}first C k(a)={a}first C k(i)= {first()k(δ)|C i→δ∈P}first C k(B(s))= {first s(C)k(δ)|B→δ∈P}where prefix k(a1...a m)=a1...a l with l=min(k,m).Example3.4In Example2.4,the nonterminals N and L occur in two in-stances(C,A)and(C,E).Respectively,first(C,A)1(N)={c}first(C,A)1(L)={ε,c}first(C,E)1(N)={c,{,[}first(C,E)1(L)={ε,c,{,[}Definition3.5The PLR(k)transition graph has as nodes PLR(k)items and arcs labeled with either a terminal symbol,a nonterminal symbol,a parameter, or a parameter instantiation.First,we need two auxiliary notions.A path X0...X n with an arc labeled l j between X j−1and X j has parameter instance C with respect toB if either•n=0and C=B•n>0and either·l n=(s),X0...X n−1has parameter instance D with respect to B,and C=s(D),or·l n is not an instantiation and X0...X n−1has parameter instance C with respect to B.A node X has parameter instance C if there is a nullary nonterminal B,a production B→δ∈P,a terminal string v,and a path from node[B→•δ,v] to X that has parameter instance C with respect to().The transition graph is then defined as the smallest graph G such that the following conditions hold.•[S→•α,ε]is a node of G,if S→α∈P(S is the start symbol).•If X=[A→β•aγ,v]is a node of G,then Y=[A→βa•γ,v]is a node of G and X a−→Y is a labeled arc in G.•If X=[A→β•B(s1,...,s k)γ,v]is a node of G(for k≥0),B→δ∈P, X has parameter instance C,and v ∈first C k(γv),then Y=[B→•δ,v ]is a node of G and X(s1,...,s k)−→Y is a labeled arc in G.•If X=[A→β•B(s1,...,s k)γ,v]is a node of G(for k≥0),then Y= [A→βB(s1,...,s k)•γ,v]is a node of G and X B−→Y is a labeled arc in G.•If X=[A→β•iγ,v]is a node of G,then Y=[A→βi•γ,v]is a node of G and X i−→Y is a labeled arc in G.•If X=[A→β•iγ,v]is a node of G,X has parameter instance C= (C0,...,C l−1),C i→δ∈P,and v ∈first C k(γv),then Y=[C i→•δ,v ]is a node of G.Example3.6Figure1is the transition graph for the example grammar for lookahead k=0.In thefigure,terminal symbols are indicated with double quotes.The lookahead part of the items is omitted(since it is always empty). The inclusion of C→•,is caused by N→N(0,1)•01in instances(C,A)or (C,E).The inclusion of A→•c:E is caused by N→•1in instance(C,A).S −> . EE −> . "c"E −> "c" .E −> . "{" L(C,A) "}"E −> "{" . L(C,A) "}" E −> . "[" L(C,E) "]"E −> "[" . L(C,E) "]"L −> .N −> . 1N −> 1 .L −> . N(0,1)E −> "[" L(C,E) . "]"E −> "[" L(C,E) "]" .N −> . N(0,1) 0 1N −> N(0,1) . 0 1N −> N(0,1) 0 . 1N −> N(0,1) 0 1 .L −> N(0,1) . C −> . ","C −> "," .A −> . "c" ":" E A −> "c" . ":" E A −> "c" ":" . E A −> "c" ":" E .S −> E .E ()c 1(){(C,A)(C,E)(C,A)(C,E)[L N (C,A) (C,E)N 01,c:E()(C,A) (C,E)()(C,A) (C,E)(C,A) (C,E)]Fig.1.Transition Graph of Example GrammarThe figure shows that the subgraph for the parameterized nonterminals is shared among their instances.In traditional LR parsing,the state of a parser is the closure of a set of kernel items.In parameterized LR parsing the state of a parser is a mapping from tuples of nullary nonterminals to a set of PLR(k)items.The notion of closure corresponds to a notion of consistency of a state.Definition 3.7A PLR(k)pre-state is a mapping that sends a tuple of nullary nonterminals to a set of PLR(k)items.A PLR(k)pre-state q is consistent with respect to transition graph G if,for all C ∈dom (q ),[A →β•γ,v ]∈q (C )and [A →β•γ,v ](s )−→Y in G implies that Y ∈q (s (C )).A PLR(k)state is a consistent PLR(k)pre-state.The function close maps a PLR(k)pre-state q to the smallest PLR(k)state containing q .The close function performs all instantiation of parameters by enforcing the consistency condition.This happens to be the only place in a PLR parser,where instantiation plays a role!The goto function implements a state transition in the parser.It maps aPLR(k)pre-state and a grammar symbol to a PLR(k)state.goto(q,a)=close C→{[A→βa•γ,v]|[A→β•aγ,v]∈q(C)}C∈dom(q)goto(q,B)=close C→{[A→βB(s)•γ,v]|[A→β•B(s)γ,v]∈q(C)}∪{[A→βi•γ,v]|[A→β•iγ,v]∈q(C),C i=B}C∈dom(q)Example3.8Continuing the running example further,the initial state of the parser is the closure of the PLR(0)pre-state{()→{[S→•E]}},that is ()→{[S→•E],[E→•c],[E→•{L(C,A)}],[E→•[L(C,E)]]} Applying the goto function with terminal{as argument yields()→{[E→{•L(C,A)}],[A→•c:E]}(C,A)→{[L→•],[L→•N(0,1)],[N→•1],[N→•N(0,1)01]}For comparison,the transition with terminal[yields()→{[E→[•L(C,E)]]}(C,E)→{[L→•],[L→•N(0,1)],[N→•1],[N→•N(0,1)01]} Hence,the parsing state becomes modular with the parameterized part being reusable(but requiring a two-stage mapping to compute goto).4PLR(k)Parsing AlgorithmWe adhere to the functional description of LR parsing given by Leermakers [13]and exploited in earlier work by one of the authors[18].The idea of the functional description is that a parser is considered as a nondeterministic function mapping an input string to a pair of a PLR(k)item and a new string. The specification of a parser is thus([A→β•γ,v],w )∈parse(w)iffw=w w ∧γ∗⇒w ∧prefix k(w )=v 4.1Nondeterministic ParsingIn our specific case,the parser function depends on a PLR(k)state and—instead of dealing with nondeterministic functions—it will return a set of pairs of PLR(k)item and unconsumed input.Interestingly,the main parserfunction does not change with respect to the previous formulation[17].)=[q](w,c1...c nactive(q)letrecc0(X,w)=let q =goto(q,X)in[q ](w,c0c1...c nactive)(q ) in ({c|α|(A,w)|[A→α•,v]∈q,prefix k(w)=v}∪{c0(a,w )|w=a·w ,a∈nextterm(q)})The parsing function[q]has two parameters,the input string and a list of continuations.Each continuation corresponds to a function that shifts on a nonterminal whenever a reduction occurs.Calling the continuation performs the reduce operation:“pop the right-hand side of the production from the parse stack and then push the state corresponding to the left-hand side.”For readers used to the stack-based implementation,it is probably best to regard the list c1...as a representation of the topmost items of the parse stack.The function c0performs a shift action by pushing the continuation corre-sponding to the current state(itself)on the list of continuations and changing the state according to the symbol X.The auxiliary functions need to be extended to PLR(k)states.The func-tion nactive:PLR-state→N determines the maximum number of continua-tions required to perform a reduce action in any state reachable from state q. It is the maximum number of symbols to the left of the dot in any item in q.nactive(q)=max{|β||C∈dom(q),[A→β•γ,v]∈q(C)} The other auxiliary function nextterm:PLR-state→P(Σ)yields the set of terminal symbols immediately to the right of the dot in any item in a state.nextterm(q)={a|C∈dom(q),[A→β•aγ,v]∈q(C)}4.2Deterministic ParsingThe above,nondeterministic parsing function performs generalized LR pars-ing[12,21,15]because it explores all parsing alternatives“concurrently.”To obtain a deterministic parsing function,states with“parsing conflicts”need to be identified and ruled out.As with standard LR parsing,there are two kinds of conflicts,a shift-reduce conflict or a reduce-reduce conflict.Definition4.1A PLR(k)state q has a shift-reduce conflict if there are B,C∈dom(q)(not necessarily different)such that[A→β•aγ,u]∈q(B) and[B→δ•,v]∈q(C)withfirst B k(aγu)=v.A PLR(k)state q has a reduce-reduce conflict if there are B,C∈dom(q) (not necessarily different)such that[A→β•,v]∈q(B)and[B→δ•,v]∈q(C)with A→βdifferent from B→δ.A restricted macro grammar is a PLR(k)grammar if the states extracted from the grammar’s transition graph are all free of conflicts.While the generalized shift-reduce conflict is identical to the standard no-tion,the reduce-reduce conflict turns out to be less restrictive.Here is an example that exhibits the difference with respect to the expanded grammar from Lemma2.3.Let G be given by the productionsS→L(A),S→L(B),L→ε,L→0L(0),A→a,B→bwhere the parameterized nonterminal L generates lists.(The example ab-stracts from a situation where two alternative ways of writing the items of a parameter list.)The expanded grammar has productionsS→L A,S→L B,L A→ε,L A→A L A,L B→ε,L B→B L B,A→a,B→b and the(standard LR)closure of{[S→•L A],[S→•L B]}has a reduce-reduce conflict between[L A→•]and[L B→•]already(ignoring the shift-reduce conflict of either item with[A→•a]and[B→•b]):S→•L A,S→•L B,L A→•,L A→•A L A,L B→•,L B→•B L B,A→•a,B→•b However,the PLR(0)closure of{()→{[S→•L(A)],[S→•L(B)]}}is()→{[S→•L(A)],[S→•L(B)],[A→•a],[B→•b]}(A)→{[L→•],[L→•0L(0)]}(B)→{[L→•],[L→•0L(0)]}and—according to our definition—there is no reduce-reduce conflict because the underlying production of the reduce items is L→εin both cases.Apart from the different definition of conflict,the remaining notions of conflict resolution go through as in the standard case.5Attribute EvaluationAs with standard LR(k)parsers,a PLR(k)parser can evaluate all attributes occurrences in a parse tree of an S-attributed grammar during parsing.The novelty is that attributes of parameterized nonterminals should have poly-morphic types.To see that,let’s reconsider the grammar fragment for comma separated lists from the introduction,equipped with generic semantic actions: SepList(Sep,Item):/*empty*/{s1()}|NESepList(Sep,Item){s2($1)}; NESepList(Sep,Item):Item{n1($1)}|NESepList(Sep,Item)Sep Item{n2($1,$2,$3)};In fact,Sep and Item may be regarded as type variables so that the generic type for NESepList(Sep,Item)has the form∀αβ.τ.This observation may be phrased as a type system for semantic actions of parameterized grammars.It relies on an unspecified,external typing judgment∆ e:τwhich relates a typing environment∆and an expression e to its typeτ.The only assumptions about this type system are that types may contain type variables and∀-quantification is permitted at the top-level.To derive the type of the right-hand side w{e}of a rule with semantic action e,as captured by judgmentΘ w{e}:τrequires two premises.First, A typing environment∆is created by the judgmentΘ i w⇒∆from the typing environment for nonterminals,Θ,a position in the right-hand side of a production,i,and a right-hand side of a production,w.Second,the right-hand side is the type of the semantic action in typing environment∆as derived by the external judgment∆ e:τ.Θ 1w⇒∆∆ e:τΘ w{e}:τThe next set of rules specifies the construction of the variable environment for typing the semantic action.It assumes that the action refers to attributes of right-hand side symbols by a positional notation,$i.Θ iε⇒∅Θ i+1w⇒∆Θ i aw⇒∆,$i:ΣΘ i+1w⇒∆Θ(j)=τΘ i jw⇒∆,$i:τΘ i+1w⇒∆Θ(B)=∀α1...αm.τ(∀1≤j≤m)Θ s j:τjΘ i B(s1...s m)w⇒∆,$i:τ[αj→τj]The next rule specifies an auxiliary judgment used to infer the instantiation for a parameterized nonterminal.Θ(j)=τΘ j:τΘ(B)=τΘ B:τThefinal group of rules collects the types from the productions.Thefirst rule collects the types of all right-hand sides,makes sure that their types are all equal,and that the resulting type is polymorphic with respect to the parameters of the left-hand side nonterminal.a(A)=mΘ,1:α1,...,m:αm w i{e i}:τΘ(A)=∀α1...αm.τ(∀1≤j≤m)αj/∈free(Θ,α1,...,αj−1)Θ A→w1{e1}|...|w n{e n}Finally,the productions in a grammar must be mutually consistent.dom(Θ)=N(∀p∈P)Θ pΘ P6ImplementationWe have implemented parameterized LR parsing in the context of Essence,a partial-evaluation based LR parser generator for Scheme[17].Essence differs from most other parser generators,as for example bison[5] or yacc[10],both in the way it is built and it is used.Instead of testing and debugging a parser running several edit–generate–compile–test cycles,the user solely works with a generic parser taking both a grammar and an input stream as input to develop thefinal grammar.Hence,no generation and recompilation is necessary to try out changes to a grammar.In the end, an automatic program transformation called partial evaluation produces a generated parsers from the general parser[16,18].This guarantees consistency and ensures correctness.Nonetheless users of Essence need not to have any special knowledge about partial evaluation techniques.Integrating parameterized LR parsing into Essence amounts to adapting its general parser to parameterized LR parsing.A parser generator for PLR pars-ing results again by applying a partial evaluation framework to the adapted general parser with respect to PLR(k)grammars the same way it is done for the original Essence parser.The general parser of Essence is a straightforward reformulation of a func-tional description of general LR parsers in the Scheme programming language [13,18].The integration of PLR(k)parsing resulted in implementing an addi-tional representation for PLR grammars,for parse items,and in implementing adapted versions offirst,goto,nactive and nextterm.The rest of the pars-ing infrastructure of Essence,as for example the main parser function,stays unchanged.7Related WorkParser combinators[20,9]are a highlyflexible way of specifying parsers in functional programming languages.In particular,the use of polymorphic functions and parameterized parsers is a natural way of structuring code with parser combinators.In contrast to the present work,they perform predictive or top-down parsing.Recent advances[19]have widened their scope consider-ably with respect to earlier,inefficient proof-of-concept implementations.The present work makes some of the polymorphism andflexibility that make parser combinators attractive available to the construction of LR parsers.The syntax definition formalism SDF[22]supports arbitrary context-free grammars and creates GLR parsers[12,21,15]for them.For convenience, right-hand sides may contain an extended set of regular operators.An SDF specification also defines a lexical syntax.SDF includes an abbreviation mech-anism which works by expansion.Extensions of LR parsing with regular operators on the right-hand sides of productions have been explored by Chapman[2].He extends the stan-。

相关文档
最新文档