Noutați

Learn C++ Optimization With A Genetic Algorithms Example

Solving C++ optimization problems are one of the areas of all quantitative disciplines from social science, economics to engineering fields such as computer science. Genetic Algorithm (GA) is a kind of machine learning process that is used to generate high-quality solutions to optimization and search problems by relying on biologically inspired operators such as mutation, crossover, and selection. In this post, we explain how you can achieve optimization using artificial intelligence techniques. The Genetic Algorithm that we use here below was first mentioned by Željko Kovačević (Embarcadero MVP). Željko has amazing VCL Examples and blog posts about C++ Builder. He gave me this example below as a console app about GA and allowed me to release it free, but credits of this code may require contact with him. Then I improve and simplify (I can’t ofc) it for the C++ Builder and C++ Builder CE. Here, the field and codes below may be harder for beginners but I am sure this post may help how you can develop your scientific applications with C++ Builder CE. What is a Genetic Algorithm? In computer science and research, a Genetic Algorithm (GA) is an algorithm that is used to solve optimization problems by evolving towards better solutions, just as sentient beings do in nature. Genetic Algorithm (GA) is a metaheuristic inspired by the process of natural selection that belongs to the larger class of evolutionary algorithms. Genetic algorithms are commonly used to generate high-quality solutions to optimization and search problems by relying on biologically inspired operators such as mutation, crossover, and selection. In a Genetic Algorithm, first, we create an initial population, then we iterate in a loop by calculating the fitness value, selection, crossover, and mutation steps as below, Genetic Algorithm Schema Genetic Algorithms are one of the older AI/ML methods developed to solve some problems such as solving sudoku puzzles. Genetic Algorithms and Fuzzy Logic were very popular in the 1990s. A typical genetic algorithm requires: A genetic representation of the solution domain, a fitness function to evaluate the solution domain. How to develop a genetic algorithm with C++ Builder? In our optimization example in C++, we develop an optimization algorithm such as Genetic Algorithm about our chosen field. Now let’s explain quickly what we mean by that. First, we have a global Input value that represents a value (number) for which Genetic Algorithm (GA) is trying to find its binary representation.   unsigned int inputValue = 1234567890;   We have individuals to evaluate with genetic algorithms, so we can create this class below. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22   class Individual { public: std::vector gene = std::vector(32); // number of bits unsigned int fitness{ std::numeric_limits::max() };   void evaluate() { unsigned int number = toNumber(); if (number

Read More

How To Create A Real Mac App Step By Step Guide

Hello developers. Our previous sessions in our Winter Webinars series which showed you how to create a real Android app step by step“, how to create a real iOS app (even if you do not have a mac), and how to create a real windows app were extremely popular. During the sessions I showed how to use RAD Studio 12 to create multi-platform apps to target Android, iOS and Windows devices. Building on that is the following session which shows how to create a real Mac app, using RAD Studio 12 and Delphi. The session focuses a little on the real benefits of Firemonkey FXM frameworks rather than just creating a Mac app. The main reason is it’s really easy to create a Mac app with RAD Studio, but also because the Winter Webinar series is iterative – building on the things we learned in prior webinars and adding to that knowledge. Over the next few weeks, we’ll start to actually add proper functionality and link things up to the cloud, the web, each other, and even a robot arm. Stick around; we’re going to see that RAD Studio can do pretty much anything you can dream of – and do it without needing to be a super hardcore software developer too. If you want to register, go to: https://lp.embarcadero.com/webinar-registration In this article you can catch the full replay including the questions and answers. If you watch on YouTube please hit the “like” and “subscribe” buttons to make sure you get notifications of all the videos in the Winter Webinar series. Hitting “like” and “subscribe” on YouTube will not add you to any mailing lists from Embarcadero – the only effect is for YouTube to send you a notification the next time we upload a new webinar or start a live broadcast. Where can I see the replay of the “How To Create A Real Mac App Step By Step Guide” webinar? Here’s the full replay of the video. All the video replays are also uploaded to our YouTube channel. You can also find them in the “Learn” section of the RAD Studio IDE Welcome page. The plan is, as time goes on, for me to fill that “Learn” tab with a whole series of videos which take you through every aspect of creating cross-platform and desktop apps with RAD Studio on Windows, macOS, Linux, iOS, and Android. You can view the replay of the webinar, including questions and answers here: Where can I get the slides for the “How To Create A Real Mac App” step by step guide? Here are all the slides for “How To Create A Real Mac App Step By Step Guide”. Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder. Design. Code. Compile. Deploy. Start Free Trial   Upgrade Today    Free Delphi Community Edition   Free C++Builder Community Edition

Read More

Useful C++ 17 Features That You Should Learn

Hello Developers, in my opinion, the C++17 standard is one of the biggest milestones in the history of C++ development. It is amazing with a lot of new features, and in this weekly round post, we have another three important features that you should learn. We explain the new optional class template, we teach you how to use alias templates for traits and we explain what std::any is and how you can use it. Our educational LearnCPlusPlus.org site has a broad selection of new and unique posts with examples suitable for everyone from beginners to professionals alike. It is growing well thanks to you, and we have many new readers, thanks to your support! The site features a treasure-trove of posts that are great for learning the features of modern C++ compilers with very simple explanations and examples. RAD Studio’s C++ Builder, Delphi, and their free community editions C++ Builder CE, and Delphi CE are powerful tools for modern application development. Table of Contents Where I can I learn C++ and test these examples with a free C++ compiler? How to use modern C++ with C++ Builder? How to learn modern C++ for free using C++ Builder? Do you want to know some news about C++ Builder 12? Where I can I learn C++ and test these examples with a free C++ compiler? If you don’t know anything about C++ or the C++ Builder IDE, don’t worry, we have a lot of great, easy to understand examples on the LearnCPlusPlus.org website and they’re all completely free. Just visit this site and copy and paste any examples there into a new Console, VCL, or FMX project, depending on the type of post. We keep adding more C and C++ posts with sample code. In today’s round-up of recent posts on LearnCPlusPlus.org, we have new articles with very simple examples that can be used with: The free version of C++ Builder 11 CE Community Edition or a professional version of C++ Builder or free BCC32C C++ Compiler and BCC32X C++ Compiler or the free Dev-C++ Read the FAQ notes on the CE license and then simply fill out the form to download C++ Builder 11 CE. How to use modern C++ with C++ Builder? The C++17 standard came with a lot of great features and std::optional was one of the main features of today’s modern C++. std::optional is a class template that is defined in the header and represents either a T value or no value. In the first post, we explain, what is optional in modern C++ and how we can use it efficiently. One of the great features of C++ is templates, they are parameterized by alias templates in C++11. Then, In C++14 and C++17, they improved C++11’s feature with several template aliases whose use simplifies the traits. This feature is called “Alias Templates For Traits” and in this post, we explain that it is an alias template and how we can use alias templates with traits. Another interesting feature of C++17 was the new type std::any. std::any is a type-safe container to store a single value of any variable type. In the next post, we explain std::any in modern C++. How to learn modern C++ for free using C++ Builder? LearnCPlusPlus.org has been producing full of educational articles about C and modern C++ that can be used with C++ Builder, C++ Builder CE, Dev-C++, BCC Compiler and some other […]

Read More

Swimm Adds Generative AI Chat Tool for Documentation

Swimm today announced it has added a chat tool that enables developers to use natural language to surface insights into code. Company CEO Oren Toledano said the /ask Swimm tool makes it simpler to launch queries that enable developers to better understand how code was constructed. The /ask Swimm tool aggregates documentation along with other related data to surface factors that are not evident in the code itself, such as documentation of business decisions, product design considerations and decisions concerning why specific architectural choices were made. It automatically captures and updates code-related knowledge to provide a continuous feedback loop as code, documentation, files and repositories are created and updated to provide deeper insights into code that goes beyond what might have been actually documented. The overall goal is to provide a mechanism that enables developers to understand how and why code was constructed within the context of an integrated development environment (IDE), said Toledano. Swimm has previously made available a platform that uses generative AI platform to create a static analysis of documentation. That capability should make it simpler for organizations to track documentation at a time when generative AI platforms such as ChatGPT are exponentially increasing the amount of code being written. In theory, those platforms should be able to also create documentation for that code, but there will still be a need for tools to track and analyze it. In the longer term, Swimm plans to continue to extend its usage of generative AI to provide deeper levels of insights across entire applications and software ecosystems to address that challenge, noted Toledano. In the short term, however, it’s clear that AI is making developers more productive than ever. In fact, the volume of code being generated might soon overwhelm existing DevOps pipelines and workflows. Most DevOps teams will need to revamp those workflows as the pace at which more applications than ever are being developed and deployed faster than ever. It’s still early days as far as generative AI adoption is concerned, but it’s clear many developers are already using it to write code. How much of that code makes it into a production environment is difficult to determine, but a lot of that code is going to be of varying quality. A general-purpose AI platform such as ChatGPT was trained using code collected from all across the web. The code generated by these platforms is only as good as the examples used to train it, all of which were created by human developers who may have made mistakes, such as including code that has known vulnerabilities. Regardless of whether code was generated by a machine or a human, the probability that documentation will need to be analyzed as part of a code review process is always high. The challenge and the opportunity is to determine the best way to apply AI to a longstanding challenge that is now being exacerbated by the existence of AI tools that, with each passing day, are only becoming more accessible to developers.

Read More

What Are The Elementary String Conversions That Come With C++ 17?

In addition to many beneficial features of C++ 17, there are elementary string conversions introduced in that specification. The std::to_chars() and std::from_chars() are defined in header to do conversions between numeric values to strings or strings to numeric values without considering locale-specific conversions. In this post, we explain the std::to_chars() and std::from_chars() that come with C++17. What Are The Elementary String Conversions That Come With C++ 17 ? What is std::to_chars()? The std::to_chars() is defined in header and is used to convert numeric values into a character string within the given valid range. The std::to_chars() is designed to copy the numeric value into a string buffer, with a given specific format, with the only overhead of making sure that the buffer is big enough. You don’t need to consider locale-specific conversions. Here is the syntax of std::to_chars in C++ 17.   std::to_chars_result  to_chars( char* first, char* last, value, int base = 10 );   Here is a simple example.   std::string str= “abcdefgh”; const int ival = 10001000; const auto con = std::to_chars( str.data(), str.data() + str.size(), ival);   In floating point number conversions, std::chars_format types can be used (i.e. std::chars_format::fixed, std::chars_format::scientific, std::chars_format::general,…) What is std::from_chars()? The std::from_chars() is defined in the header and used to convert the string data in a given range to a value (string to int, string to float operations) if no string characters match the pattern or if the obtained value is not representable in a given type of value, then the value has remains unchanged. The std::from_chars() is a lightweight parser that does not need to create dynamic allocation, and you don’t need to consider locale-specific conversions. Here is the syntax of std::from_chars in C++ 17.   std::from_chars_result from_chars( const char* first, const char* last, &value, int base = 10 );   Here is a simple example.   std::string str= “10001000”; int vali; auto [ptr, ec] = std::from_chars(str.data(), str.data() + str.size(), vali);   Is there a full example to elementary string conversions that comes with C++ 17? Here is a full example about std::to_chars() and std::from_chars() in C++ 17. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38   #include #include #include   int main() { std::string str= “abcdefgh”;   // INT TO CHAR const int ival = 10001000; const auto con = std::to_chars( str.data(), str.data() + str.size(), ival);   std::cout

Read More

From Reaction to Robots: Riding the AI Wave in 2024

As we navigate another year of consistent zero-day breaches, legislative pivots, the explosion of AI tooling and threat actors growing bolder and more desperate, it’s safe to say that getting comfortable with change is a requirement for thriving in the technology industry. We occupy a notoriously unpredictable space, but that’s half the fun. Compared to many other verticals, technology—especially cybersecurity—is relatively youthful, and the future should be something we can all look forward to blossoming in sophistication alongside the technology we swear to protect. So, what can we expect in the industry in 2024? We put our heads together, looked into our crystal ball, and these were the results: Government Regulations Around AI Will Turn the Industry Upside Down It was the talk of the conference circuit in 2023, with several high-profile presentations at Black Hat, DEF CON, Infosecurity Europe and many more warning of the explosive changes we can expect from AI implementation across every industry, especially cybersecurity. As tends to happen with low barriers to entry for such transformative technology, adoption has outpaced any official regulation or mandates at the government level. With significant movements in general cybersecurity guidelines and benchmarks around the world, including CISA’s Secure-by-Design and -Default principles in the U.S. and similar initiatives from the UK and Australian governments, it is essentially a foregone conclusion that regulations around AI use will be announced sooner rather than later. While much of the debate surrounding the mainstream use of AI tooling and LLMs has centered around copyright issues with training data, another perspective delves into how AI is best used in cybersecurity practices. When it comes to coding, perhaps its most human quality is its similar hardship in displaying contextual security awareness, and this factor is deeply concerning as more developers are adopting AI coding assistants in the construction of software. This has not gone unnoticed, and in a time of increased scrutiny for software vendors adopting security best practices, government-level intervention certainly would not surprise. … And Demand for AI/ML Coding Tools Will Create a Need for More Developers, not Less! Much has been written about the AI takeover, and for the better part of a year, we have been subject to a plethora of clickbait headlines that spell doom and destruction for just about every white-collar profession out there, and developers were not spared. After months of speculation and experimentation with LLMs in a coding context, we remain entirely unconvinced that development jobs are at collective risk. There is no doubt that AI/ML coding tools represent a new era of powerful assistive technology for developers, but they are trained on human-created input and data, and that has rendered the results far from perfect. Perhaps if every developer on the planet was a top-tier, security-minded engineer, we might see genuine cause for concern. However, just as the average adult driver vastly overshoots their ability (notice how everyone says they’re a great driver, and it’s always other people who lack skill? That’s a classic example of the Dunning-Kruger effect!), so too does the development community, especially when it comes to security best practices. According to one Stanford study into developer use of AI tooling, it is likely that unskilled developers using this technology will become dangerous. The study claimed that participants who had access to AI assistants […]

Read More

What Is The Class Template Variant (std::variant) in C++ 17?

In C++ Builder 12, and modern C++ the std::variant is one of the powerful features that comes with C++17. The std::variant is a discriminated union that we can work with multiple data types. It represents a type-safe union and holds one of its types in definition. What is the class template std::variant in C++ 17? The std::variant is a class template defined in  header that represents a disjoint union (or discriminated union). A value of variant contains one of an A, a B, or a C at any one time. It can be used as a multi-type variable, for example, a variable can be a float, an int, or a string. Here is the template definition since C++17:   template class variant;   Here is a simple example that shows how we can use it.   std::variant myvar; myvar = 100; // int   To get value of a variant we can use std::get (std::variant), here is how we can use it:   std::variant myvar2; myvar2 = std::get(myvar);   std::variant has many useful methods and properties that can be used in modern C++, such as index, valueless_by_exception, emplace, swap, get_if, visit, variant_size, variant_size_v, variant_npos, monostate, std::hash, and operators ( =, ==, !=, , =, ) Is there a full example about the class template variant in C++ 17? Here is an example. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23   #include #include #include   int main() { std::variant myvar;   //myvar = true; // bool myvar = 100; // int     if ( std::holds_alternative(myvar) ) std::cout

Read More

#include Diagnostics in Visual Studio

#include Diagnostics in Visual Studio Mryam Girmay January 8th, 20241 3 We’re excited to announce that the #include Diagnostics feature is now available in Visual Studio 2022 17.9 Preview 2. This new feature allows you to better understand the behavior of #include directives by providing detailed information on each directive’s references and build time.  Download Visual Studio Preview To begin utilizing this feature, activate #include diagnostics by performing a right-click in your editor to display the context menu. Then, navigate to the ‘Include Directives’ option and choose ‘Enable #include Diagnostics’.  #include References  The feature in Visual Studio allows you to analyze the usage of #include directives in your code. It shows where and how often each directive is referenced, which can be particularly useful when dealing with a long list of directives. If you find an #include directive that is infrequently used but significantly impacts your compile time, this tool will help you identify it quickly so you can take the necessary steps to optimize your code.  Once you enable #include diagnostics, you should see a line of text above each #include directive. This is the CodeLens feature in action. The text above the #include directive indicates the count of its references in your current file. Clicking this count opens a window listing these references. Selecting any reference from this list will direct you to its corresponding line of code in your project.  #include Build Time This feature presents the build time for each #include directive. To activate this, you’ll need to run Build Insights by navigating to Build -> Run Build Insights. This action will generate the necessary build time data. This allows you to easily visualize and evaluate the build time for each #include directive by comparing its usage and compilation time. The information provided by #include Diagnostics can be utilized to optimize your #include directives and improve compilation time. In addition to the information provided by the new #include diagnostics you may also want to consider checking out our documentation on C++ modules as an alternative to #include to further improve compilation time. Send us your feedback  Your feedback is invaluable to us as we strive to enhance your experience. Please feel free to leave your comments below. Alternatively, you can share your thoughts through the Visual Studio Developer Community. We’re also available on Twitter (@VisualC) and can be reached via email at visualcpp@microsoft.com. We look forward to hearing from you!    Mryam Girmay Program Manager, C++ Follow

Read More

AI a Key Driver Behind HPE’s $14 Billion Deal for Juniper

Hewlett Packard Enterprise is looking to become a more significant player in the networking space through its planned $14 billion acquisition of Juniper, a deal that it hopes will make it a more formidable rival to longtime market leader Cisco Systems. The deal, announced Tuesday after the markets closed, is a big deal in the early days of the new year for a networking industry that has become central in an IT sector that is becoming more distributed and more cloud-native. During a virtual briefing with analysts and journalists this morning, HPE CEO Antonio Neri described an HPE centered around its networking business that has AI capabilities and its GreenLake edge-to-cloud platform of IT services at its foundation. “HPE will be a new company where networking will be the core foundation of everything we do,” Neri said. “We’re going to accelerate what we call an AI-driven agenda, and that will allow us to capture this massive inflection point.” Even when the deal closes – which is expected to happen later this year or in early 2025 – HPE will still likely be in third place in the global networking space behind Cisco and Huawei, but will have a stronger portfolio that will not only include greater AI capabilities but also a stronger presence in both the enterprise and telecom spaces. Once it closes, Juniper CEO Rami Rahim will lead the combined HPE networking business and report to Neri. Juniper’s Mist AI is at the Center Unsurprisingly, AI was a key component of the deal. In a research note, Will Townsend and Patrick Moorhead, analysts with Moor Insights and Strategy, wrote that their thinking after initial news reports about a possible deal circulated was that HPE likely was looking for a “strong AI anchor” for its portfolio of hardware, software, and GreenLake IT consumption services. “AI is hot, ignited by the attention being directed toward generative AI, the underlying large language models, and many promising use cases,” Townsend and Moorhead wrote. “One could argue that beyond the AIOps capability found in the HPE Aruba Networking portfolio today, HPE needs further AI depth to remain competitive and continue to grow its top-line revenue and profitability. Juniper could deliver on that front.” Rahim called AI “the biggest inflection since the dawn of the internet itself” and added that the combination of HPE and Juniper “will be able to bring the depth and the breadth of the portfolios necessary to capture the full market opportunity that AI presents in front of us.” AI in networking is a strength for Juniper, which in 2019 bought Mist Systems and its AI technologies, including the Mavis virtual network assistant, which the analyst wrote serves “as the tip of the spear for Juniper’s reinvigorated efforts within the enterprise for WLAN, LAN, WAN, and SD-WAN solutions.” “By all measures, the Mist acquisition has been a success, with Juniper growing its enterprise install base at a faster rate than its service provider business over the last 12 to 18 months,” Townsend and Moorhead wrote. AI and Networking AI will play an increasingly important role in networking going forward, from dynamically adjusting bandwidth and self-correcting in the network for maximum uptime to quickly finding root causes for problems and deploying virtual network assistants. In a blog post last month, Liz Centoni, […]

Read More

What Is The New std::sample Algorithm In C++ 17?

The C++ 17 standard bring us a lot of useful methods, templates and algorithms. One of the great algorithms is std::sample defined in the header that samples at most n elements uniformly from a given range. In this post, we explain the std::sample algorithm and how we can use it with an mt19937 random generator. What is the std::sample algorithm in C++ 17 and beyond? The std::sample algorithm is defined in header that samples at most n elements uniformly from a given range into the output iterator and random numbers can be generated by using a random number generator function. Generally std::mt19937{} is used as random generator and std::random_device{}() is used random generator device. The std::sample algorithm is defined as a template algorithm in C++17 as shown below.   template SampleIterator sample( PopulationIterator first_in, PopulationIterator last_in,                        SampleIterator output, Distance n, URBG&& function );   Here, first_in and last_in are the iterators that defines range of input. n is number of elements to be sampled into output iterator, function is random number generator function. Is there a full example about the std::sample algorithm in C++ 17 and beyond? Here is a full example about std::sample in C++ 17. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28   #include #include #include #include #include #include   int main() { std::vector vec_in {“This”, “LearnCPlusPlus.org”, “is”, “really”, “amazing”,“!”}; std::vector vec_out;   std::cout

Read More