To achieve optical transparency in Wavelength Division Multiplexing (WDM) networks of increasing size, in terms of both the number of nodes and network span, optical amplifiers are necessary to compensate for propagation and splitting losses encountered by an optical signal from any source to any destination. A recent study showed that in small and medium size broadcast-and-select star/tree networks the necessary number of amplifiers can be minimized by allowing wavelengths to operate at different power levels. Finding this minimum number of amplifiers and their locations requires solving a Mixed Integer Non-Linear Problem. This paper presents a generalization of the above problem, called Generalized optimal Placement of optical Amplifiers in broadcast-and-select WDM networks, or GPA problem. In the GPA problem the number of optical amplifiers is minimized taking into account that the fiber layout may include star/tree and ring topologies, and the installation and maintenance costs of the amplifier may depend on its location, i.e., solutions with equal number of amplifiers may not be equally appealing. The GPA problem is solved using a Simulated Annealing (SA) approach whose flexibility makes it an ideal heuristic to cope with the various fiber layouts and the location dependent cost issue. In addition, the SA approach offers the advantage of escaping local minima of the cost function, thus providing satisfactory solutions independent of the chosen initial solution. The optimal solution of the GPA problem provides a versatile technique to design cost effective WDM networks based on various fiber layouts, taking into account other practical constraints, such as the installation and management costs of the necessary optical amplifiers.