Databases

deneme

Lanciare un prodotto digitale di successo richiede un processo ben strutturato e un'adeguata pianificazione. Ma da dove iniziare? E come trasformare la tua idea in un prodotto reale? In questa guida passo-passo, ti forniremo tutte le informazioni necessarie per creare e lanciare il tuo prodotto digitale con successo.

deneme
SQL Intro
SELECT
Columns
Operators
Escapes
ORDER BY
DISTINCT
Previous PostSQL 101: Understanding Basic SELECT Statements for Querying
Next PostLatest post!
User Profile Picture

Explain the primal-dual method to someone completely new to algorithms and graph theory.

ChatGPT Profile Picture

Alright! Let's start with a simple analogy before diving into the specifics of the primal-dual method:

Analogy: Shopping on a Budget

Imagine you are shopping for fruits with a limited budget. You want to buy as much fruit as possible without exceeding your budget. On the other side, the shopkeeper wants to sell the fruits at a price where he can earn the most profit without losing customers. In this situation:

  • Your goal of maximizing the amount of fruit represents the "primal" problem.
  • The shopkeeper's goal of pricing the fruits represents the "dual" problem.

In an ideal world, the amount you are willing to pay for each fruit (based on your budget and desire) would match exactly with the prices the shopkeeper sets, resulting in the most efficient shopping transaction for both of you.

Now, translating this analogy to the realm of algorithms:

Primal-Dual Method

The primal-dual method is an approach used primarily in optimization problems. In many of these problems, you have a primary (or "primal") problem that you want to solve, but there's also a related "dual" problem that offers a different perspective. Often, by solving the dual problem, we can gain insights into the primal problem or vice versa.

  1. Primal Problem: This is the original problem you want to solve. For example, it might be about finding the shortest path in a graph or maximizing some kind of profit.

  2. Dual Problem: This is a related problem that is derived from the primal problem. The solution to the dual problem often gives a bound or limit to the solution of the primal problem. If the solutions to the primal and dual problems are the same, we have an optimal solution.

The primal-dual method involves:

  • Starting with an initial feasible solution to the dual problem.
  • Using this solution to guide the search for a feasible solution to the primal problem.
  • Repeatedly updating both solutions until they converge to an optimal solution.

Why is it useful?

The power of the primal-dual method lies in the fact that while the primal problem might be hard to solve directly, its dual problem might be easier. Or, solving the dual can give us insights, bounds, or approximations to the primal solution.

Connection to Graph Theory: In graph theory, there are many problems (like network flow problems) where the primal might represent a flow configuration on the graph, and the dual might represent some sort of cost or capacity constraint. The primal-dual method can be applied to get efficient solutions for such problems.

Conclusion: Just like in our shopping analogy, where both you and the shopkeeper are trying to optimize your outcomes (with buying fruits and pricing them), in algorithms, the primal and dual problems offer two sides of the same coin. Solving or approximating one can give us valuable information about the other!

The first line, 86 60 67..., can be translated into:

  • Student 0 -> Student 1 = 86
  • Student 0 -> Student 2 = 60
  • Student 0 -> Student 3 = 67

Let's do the same thing for the second line, 76 0 74...:

  • Student 1 -> Student 0 = 76
  • Student 1 -> Student 2 = 0
  • Student 1 -> Student 3 = 74

Warning: Discrete math, graph theory, and combinatorial optimization ahead! If you're unfamiliar with the mathematical symbols used in this writeup, reference this dropdown:

Complicated Math Symbols
  • \sum - Summation
  • \in - Element of
  • \notin - Not an element of
  • \subset - Proper subset of
  • \subseteq - Subset of
  • \emptyset - Empty set
  • \forall - For all
  • \exists - There exists
  • \nexists - There does not exist
  • \in - Element of
  • \notin - Not an element of
  • \ni - Contains as member
  • ∌\not\ni - Does not contain as member
  • \setminus - Set minus (drop)
  • \oplus - Direct sum
  • \cup - Union
  • \cap - Intersection
  • xx' - Prime

Definition: A set of edges EE is defined as E(x,y)  (x,y)V2 and xyE \subset \\{(x, y)\ |\ (x, y) \in V^2 \textrm{ and } x \neq y\\}. By this definition, xx and yy are the vertices that are connected to the edge ee, called the endpoints. It can also be said that ee is incident to xx and yy.

info: A set of edges EE is defined as E(x,y)  (x,y)V2 and xyE \subset \\{(x, y)\ |\ (x, y) \in V^2 \textrm{ and } x \neq y\\}. By this definition, xx and yy are the vertices that are connected to the edge ee, called the endpoints. It can also be said that ee is incident to xx and yy.

Definition: A set of edges EE is defined as E(x,y)  (x,y)V2 and xyE \subset \\{(x, y)\ |\ (x, y) \in V^2 \textrm{ and } x \neq y\\}. By this definition, xx and yy are the vertices that are connected to the edge ee, called the endpoints. It can also be said that ee is incident to xx and yy.

theorem: A set of edges EE is defined as E(x,y)  (x,y)V2 and xyE \subset \\{(x, y)\ |\ (x, y) \in V^2 \textrm{ and } x \neq y\\}. By this definition, xx and yy are the vertices that are connected to the edge ee, called the endpoints. It can also be said that ee is incident to xx and yy.

flag: A set of edges EE is defined as E(x,y)  (x,y)V2 and xyE \subset \\{(x, y)\ |\ (x, y) \in V^2 \textrm{ and } x \neq y\\}. By this definition, xx and yy are the vertices that are connected to the edge ee, called the endpoints. It can also be said that ee is incident to xx and yy.

default: A set of edges EE is defined as E(x,y)  (x,y)V2 and xyE \subset \\{(x, y)\ |\ (x, y) \in V^2 \textrm{ and } x \neq y\\}. By this definition, xx and yy are the vertices that are connected to the edge ee, called the endpoints. It can also be said that ee is incident to xx and yy.


#include "main.h"

static void Configure_LEDS(void);
static void Configure_SPI1(void);

int main(void)
{
	int8_t x, y, z;

// Configure peripherals
	Configure_LEDS();
	Configure_SPI1();

// Initiating accelerometer LIS3DSH
	SPI_Tx(0x20U, 0x67U); // CTRL_REG4: output data rate = 100Hz, continuous update, x,y,z enable
	SPI_Tx(0x24U, 0x48U); // CTRL_REG5: Anti-aliasing filter bandwidth=200Hz, full scale = 4g

// Infinite loop
	while (1)
	{
		x = SPI_Rx((uint8_t) 0x29U);
		y = SPI_Rx((uint8_t) 0x2BU);
		z = SPI_Rx((uint8_t) 0x2DU);

		if (x < -20) SetPin(GPIOD, PIN_12);
		else ResetPin(GPIOD, PIN_12);
		if (x > 20) SetPin(GPIOD, PIN_14);
		else ResetPin(GPIOD, PIN_14);
		if (y < -20) SetPin(GPIOD, PIN_15);
		else ResetPin(GPIOD, PIN_15);
		if (y > 20) SetPin(GPIOD, PIN_13);
		else ResetPin(GPIOD, PIN_13);
	}
}

function greet(name) {
  console.log(`Hello, ${name}!`);
}

In fact, most of the projects on this site will require cloud interaction of some sort—particularly with AWS's serverless products.

Getting Started

To use AWS in these projects, we'll need to set up an account, the CLI, and the SDK.

Create an account

If you don't already have an account then sign up here.

Foo

Once you are signed up, you should be able to log in to the AWS Console. It might look overwhelming if you're seeing for the first time.

Install the CLI

The AWS CLI is a command-line application that lets you interact with your AWS account from the terminal. It's available on all platforms.

If you are a proficient Python user, you can just install it with pip.

pip install awscli

Otherwise, check out the official instructions.

Once installed, you should be able to run this command from the terminal to see its version.

aws --version

Create an IAM user

The CLI will access your AWS account via an "IAM user." You can create one from the Users page in your IAM console.

Once the user is created, you'll need to generate access keys (passwords, essentially) for it.

Your access keys should look something like this:

Access key ID: AKIAIOSFODNN7EXAMPLE
Secret access key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

Configure the CLI

Next you need to configure the CLI so that it can access your AWS account via the IAM user.

Basically, just run this command and paste in your access keys.

aws configure

Additionally, you'll also be asked for a default region and default output format.

You may leave them empty—but generally I like to use:

Default region name [None]: us-east-1
Default output format [None]: json

Configuration files

Once configured, the AWS CLI saves the credentials and region/format profiles to your computer. They are typically in these locations:

~/.aws/credentials
~/.aws/config

You can open them up and edit them if you like or just run aws configure again to change them.

Test the CLI!

Now you should be able to use your CLI to access AWS. For example, I should be able to see the S3 buckets I have in us-east-1:

aws s3 ls

2020-12-09 22:36:32 blog.pixegami.com
2020-12-27 00:04:52 cloud-archiver.5dac84a54677.archivetest

Generally, everything that can be done in the console can also be done in the CLI. Check out the full reference guide here.

AWS SDK

Finally, to use AWS directly from your application code, you need to download the SDK for the language you work with.

The SDKs can be configured in different ways as well, but by default it usually uses the same profiles and credentials stored by your aws configure.

That's it!

You're all set to start using AWS.

Why AWS?

When we bring "the cloud" into a project, it's usually because there's some capability we'd like to add.

  • Hosting for a website or service.
  • File or data storage.
  • On-demand computation.
  • Authentication.

And there's many viable solutions to choose from—Azure, Google Cloud, Firebase, Digital Ocean.

So why could you choose AWS over any of these alternatives? From a new user's perspective:

  • Largest marketshare (at 30%) which roughly translates to lots of community resources and job opportunities.
  • Most services available (175+) which means more tools at your disposal, well-integrated under one umbrella.

On the flip-side, the biggest drawback is its upfront complexity.

Personally though, the reason I use AWS is because it's the technology I'm most familiar with.

Why Serverless?

It's cheaper. Most cloud "getting started" guides will show you how to spin up a server—a mercenary rented computer that stays online 24/7 to do your bidding.

But for most of my projects, I'm going utilize technology that doesn't require a hosted server. In particular:

ServicePurpose
S3File storage
DynamoDBDatabase
LambdaCompute engine

Their on-demand pricing means the cost scales with usage. There is a free tier, and it only begins to cost money if usage exceeds a certain amount.

For small projects with light traffic, this usually translates to monthly costs of less than a dollar (if not completely free).

In comparison, the price of hosting a server typically starts at $5.00 per month.

Continue Learning

Previous PostSQL 101: Understanding Basic SELECT Statements for Querying
Next PostLatest post!
EK
Emre Kalaycı